home *** CD-ROM | disk | FTP | other *** search
/ PC User 2003 January / Disc 3 / Amethyst.iso / rl / launch / floppy / linuxrc < prev    next >
Encoding:
Text File  |  2002-11-06  |  111.8 KB  |  4,625 lines

  1. #!/bin/sh
  2. #
  3. # linuxrc - automatic hardware probing, source mounting and lizard calling
  4. #
  5. # Copyright (C) 1999-2001 Ralf Flaxa, Caldera (Deutschland) GmbH,
  6. #                         Erlangen, Germany
  7. #
  8. # $Id: linuxrc,v 1.239 2001/03/13 12:58:53 rf Exp $
  9. #
  10. #
  11. # Required external binaries still used by this linuxrc:
  12. # ======================================================
  13. # agetty
  14. # bdflushd
  15. # bootpc
  16. # cat
  17. # chmod
  18. # chown
  19. # cut
  20. # date !
  21. # do_netcalc
  22. # fgrep
  23. # freeramdisk
  24. # get_val
  25. # gzip
  26. # gunzip
  27. # hostname
  28. # ifconfig
  29. # insmod
  30. # kill
  31. # klogd
  32. # libc
  33. # ln
  34. # losetup
  35. # lsmod
  36. # mkdir
  37. # mknod
  38. # mount
  39. # ps
  40. # rm
  41. # route
  42. # sed
  43. # set_val
  44. # sh
  45. # sleep
  46. # swapon
  47. # sync
  48. # sysinfo
  49. # syslogd
  50. # touch
  51. # umount
  52. # uname
  53. # updated
  54. #
  55. # Required external files still used by this linuxrc:
  56. # ===================================================
  57. # /dev/*
  58. # /etc/fstab
  59. # /etc/hosts
  60. # /etc/lizard.cnf
  61. # /etc/passwd
  62. # /etc/rc.d/rc.rootfs
  63.  
  64. #
  65. # Global settings
  66. #
  67. export PATH="/sbin:/usr/sbin:/bin:/usr/bin"
  68. export TERM=linux
  69. export BOOT_IMAGE
  70. export ER_FLAG
  71. export FORCE_REBOOT=false
  72. export FORCE_HWINFO=false
  73. export ANSWER
  74.  
  75. #
  76. # parse global variables and configuration for lizard
  77. #
  78. . /etc/lizard.cnf
  79.  
  80. #
  81. # Functions
  82.  
  83.  
  84. Debug()
  85. {
  86.     echo "$@" >> $FILE_LOG_DEBUG
  87.     echo "$@" >> /var/log/lizard
  88. }
  89.  
  90.  
  91. Info()
  92. {
  93.     echo "$@" | sed 's/://g'
  94. }
  95.  
  96.  
  97. Error()
  98. {
  99.     chvt 1
  100.     echo "Error: $@"
  101.     echo "press <return> to abort."
  102.     read ans
  103. }
  104.  
  105.  
  106. Panic()
  107. {
  108.     chvt 1
  109.     echo "Panic: $@" >> /dev/console
  110.     echo "Panic: $@" >> $FILE_LOG_DEBUG
  111.     echo "press <return> to continue or \"sh\" for a shell." >> /dev/console
  112.     echo "press <return> to continue or \"sh\" for a shell." >> $FILE_LOG_DEBUG
  113.     read ans
  114.     if [ "$ans" = "sh" ]; then
  115.         echo "Spawning shell. Press <exit> to continue when done." >> /dev/console
  116.         /bin/sh
  117.     fi
  118. }
  119.  
  120.  
  121. Kill_Proc_By_Name()
  122. {
  123.     local name
  124.     local pids
  125.     local i
  126.  
  127.     for name in $@ ; do
  128.         pids="`ps ax | fgrep "$name" | fgrep -v fgrep | cut -c1-6 `"
  129.         for i in $pids ; do
  130.             sync
  131.             case "$name" in
  132.             "booter")
  133.                 kill -15 $i > /dev/null 2>&1
  134.                 ;;
  135.             "XF86_VGA16")
  136.                 kill -15 $i > /dev/null 2>&1
  137.                 sleep 1
  138.                 kill -15 $i > /dev/null 2>&1
  139.                 ;;
  140.             *)
  141.                 kill -1 $i > /dev/null 2>&1
  142.                 kill -9 $i > /dev/null 2>&1
  143.                 ;;
  144.             esac
  145.         done
  146.     done
  147. }
  148.  
  149.  
  150. # simple init replacement
  151. Respawn_getty()
  152. {
  153.     case $2 in
  154.     start)
  155.         while [ ! -f /etc/nologin ] ; do
  156.             touch /etc/$1.active
  157.             /sbin/agetty 38400 $1 linux
  158.         done
  159.         rm -f /etc/$1.active
  160.         ;;
  161.     stop)
  162.         touch /etc/nologin
  163.         Kill_Proc_By_Name agetty
  164.         while [ 1 ]; do
  165.             if [ -f /etc/tty$1.active ]; then
  166.                 Debug "tty$1 still active, please log out."
  167.                 sleep 2
  168.             else
  169.                 break
  170.             fi
  171.         done
  172.         ;;
  173.     esac
  174. }
  175.  
  176. Unmount_install_partitions()
  177. {
  178.     local dev
  179.     local mountp
  180.     local rest
  181.     local tries
  182.  
  183.     cd /
  184.     sync
  185.     Debug "unmounting all /mnt/root based filesystems..."
  186.     for tries in 1 2 3 ; do
  187.         while read dev mountp rest ; do
  188.             if `echo $mountp | fgrep /mnt/root >/dev/null` ; then
  189.                 umount $mountp
  190.             fi
  191.         done < /proc/mounts
  192.     done
  193. }
  194.  
  195. Unmount_All()
  196. {
  197.     cd /
  198.     sync
  199.     Debug "before unmounting all filesystems..."
  200.     sync
  201.     df >> $FILE_LOG_DEBUG 2>&1
  202.     ps auxww >> $FILE_LOG_DEBUG 2>&1
  203.     Debug "unmounting all filesystems..."
  204.     umount -a >> $FILE_LOG_DEBUG 2>&1
  205.     sync
  206.     umount $DIR_SOURCE/live >> $FILE_LOG_DEBUG 2>&1
  207.     umount $DIR_SOURCE >> $FILE_LOG_DEBUG 2>&1
  208.     umount $DIR_SOURCE_TMP >> $FILE_LOG_DEBUG 2>&1
  209.     umount $DIR_LIZARD >> $FILE_LOG_DEBUG 2>&1
  210.     umount $DIR_TARGET >> $FILE_LOG_DEBUG 2>&1
  211.     umount /mnt >> $FILE_LOG_DEBUG 2>&1
  212.     umount /root >> $FILE_LOG_DEBUG 2>&1
  213.     umount /proc/bus/usb >> $FILE_LOG_DEBUG 2>&1
  214.     # proc is mounted multiple times for some reason
  215.     while umount /proc ; do true ; done >> $FILE_LOG_DEBUG 2>&1
  216.     # try again.
  217.     umount -a >> $FILE_LOG_DEBUG 2>&1
  218. }
  219.  
  220.  
  221. Breakpoint()
  222. {
  223.     local really=false
  224.  
  225.     if [ "X$1" = 'X--force' ]; then
  226.         really=true
  227.         shift 1
  228.         Debug "forced breakpoint: $@"
  229.     fi
  230.     if [ "$ER_FLAG" = "911" ]; then
  231.         Debug "er=911 breakpoint: $@"
  232.         really=true
  233.     fi
  234.     if [ "$really" = "true" ]; then
  235.         Debug "login on tty2 and fix whatever is necessary ;-)"
  236.         Debug "after that switch back to tty5 and press <return> to continue."
  237.         read ans < $FILE_LOG_DEBUG
  238.         Debug "continuing..."
  239.     fi
  240. }
  241.  
  242.  
  243. Swapoff_All()
  244. {
  245.     # release all swap partitions
  246.     for i in `cat /proc/swaps | sed '1d' | cut -d' ' -f 1` ; do
  247.         swapoff $i
  248.     done
  249. }
  250.  
  251.  
  252. Mini_init()
  253. {
  254.     local i
  255.  
  256.     case $1 in
  257.     boot)
  258.         mount /proc
  259.         # disable screen blank
  260.         echo "]"
  261.  
  262.         updated &
  263.         bdflushd &
  264.  
  265.         mount -n -o rw,remount /
  266.         rm -f /fastboot
  267.         rm -f /etc/mtab*
  268.         mount -avt nonfs,nomsdos,nohpfs >> $FILE_LOG_DEBUG 2>&1
  269.         swapon -a
  270.         rm -f /var/lock/LCK*
  271.         rm -f /var/run/*
  272.         rm -rf /tmp; mkdir /tmp; chmod 1777 /tmp
  273.         touch /var/run/utmp
  274.         chmod 644 /var/run/utmp
  275.  
  276.         # preparing modules area
  277.                 for i in kernel/drivers/block \
  278.                         kernel/drivers/cdrom \
  279.                         kernel/drivers/net \
  280.                         kernel/drivers/ide \
  281.                         kernel/drivers/parport \
  282.                         kernel/drivers/pnp \
  283.                         kernel/drivers/sound \
  284.                         kernel/drivers/scsi \
  285.                         kernel/drivers/usb \
  286.                         kernel/net/sunrpc \
  287.                         kernel/fs \
  288.                         pcmcia ; do
  289.             mkdir -p /lib/modules/`uname -r`/$i
  290.         done
  291.  
  292.         if [ -x /sbin/syslogd ]; then
  293.             /sbin/syslogd
  294.         fi
  295.         if [ -x /sbin/klogd ]; then
  296.             /sbin/klogd
  297.         fi
  298.  
  299.         hostname noname
  300.  
  301.         # Allow logins
  302.         rm -f /etc/nologin
  303.  
  304.         # allow emergency handling
  305.         # prepare command line parsing
  306.         rm -f /tmp/cmdline
  307.         for i in `cat /proc/cmdline` ; do
  308.             echo $i >> /tmp/cmdline
  309.         done
  310.         if [ -n "`sed -n '/^er=/p' /tmp/cmdline | fgrep 911`" ]; then
  311.             ER_FLAG=911
  312.         fi
  313.         if [ -n "`sed -n '/^er=/p' /tmp/cmdline | fgrep hwinfo`" ]; then
  314.             FORCE_HWINFO="true"
  315.         fi
  316.         ;;
  317.     multi)
  318.         if [ -z "`sed -n '/^lizard=/s/^lizard=//p' /tmp/cmdline`" \
  319.           -o "$ER_FLAG" = "911" ]; then
  320. # jwc
  321.             Respawn_getty tty2 start &
  322.             Respawn_getty tty3 start &
  323.         fi
  324.         ;;
  325.     single)
  326.         Respawn_getty tty2 stop
  327.         Respawn_getty tty3 stop
  328.         ;;
  329.     shutdown)
  330.         # FIXME: in case of any trouble or a cmdline switch save initrd
  331.         if [ "$ER_FLAG" = "911" ]; then
  332.             Prepare_save_initrd
  333.         fi
  334.         Prepare_free_initrd
  335.         Kill_Proc_By_Name cardmgr
  336.         Kill_Proc_By_Name nfsiod syslogd klogd updated
  337.         echo "2" > /proc/sys/kernel/printk
  338.         Swapoff_All
  339.         Unmount_All
  340.         ;;
  341.     esac
  342. }
  343.  
  344.  
  345. Install_aborted()
  346. {
  347.     local ans
  348.  
  349.     chvt 7
  350.     $CMD_BOOTER add_menu "T4 Oops!  Desktop/LX installation failed!"
  351.     $CMD_BOOTER add_menu "T5 Please refer to the printed documentation."
  352.     $CMD_BOOTER add_menu "T6 Press <return> for more information."
  353.     $CMD_BOOTER show
  354.     read ans < /dev/tty7
  355.  
  356.     # Kill $CMD_BOOTER for now (until $CMD_BOOTER can handle dialogs)
  357.     Kill_Proc_By_Name booter
  358.  
  359.     # Force writing a hwinfo file in case of install failure
  360.     FORCE_HWINFO="true"
  361.  
  362.     # Force a reboot over a initrd quit
  363.     FORCE_REBOOT=true
  364.  
  365.     # tell them what happened and how to proceed
  366.     while [ 1 ]; do
  367.         echo "c" > /dev/tty1
  368.         chvt 1
  369.         cat << EOF
  370.  
  371. The Lycoris install wizard was unable to install Desktop/LX on your
  372. system. One possible reason is that your hardware is not (yet) supported
  373. by Desktop/LX. Please visit http://www.lycoris.com/ for newer versions of
  374. Desktop/LX.
  375.  
  376. Please insert a formatted floppy and type "hwinfo".  This will write an
  377. install report to your floppy in a file called hwinfo0.txt.  Edit this
  378. file, adding some comments about your hardware, and e-mail it to
  379. hwinfo@lycoris.com.  This information provides valuable feedback for us
  380. and will allow us to try to support your hardware in future versions
  381. of Desktop/LX. Please watch our web site for updates and new versions.
  382.  
  383. To write the install report to a floppy type "hwinfo".
  384. To spawn a shell type "sh".
  385. To reboot your system type "reboot".
  386.  
  387. EOF
  388.         echo -n "Your choice: "
  389.         read ans
  390.         echo 
  391.         if [ "$ans" = "hwinfo" ]; then
  392.             Write_hwinfo
  393.         elif [ "$ans" = "reboot" ]; then
  394.             break
  395.         elif [ "$ans" = "sh" ]; then
  396.             /bin/sh
  397.         else
  398.             echo "Error: invalid answer"
  399.             sleep 3
  400.         fi
  401.     done
  402.     return 0
  403. }
  404.  
  405.  
  406. Lizard_File_Glob()
  407. {
  408.     local script="$1"
  409.     local eth0_ip="$2"
  410.     local eth0_net="$3"
  411.  
  412.     local lizarddir=$DIR_LIZARD
  413.  
  414.     if [ "`echo $script | cut -c 1,1`" = '/' ]; then
  415.         lizarddir=
  416.     fi
  417.  
  418.     if [ -f $lizarddir/${script}.${eth0_ip} ]; then
  419.         echo "$lizarddir/${script}.${eth0_ip}"
  420.     else
  421.         if [ -f $lizarddir/${script}.${eth0_net} ]; then
  422.             echo "$lizarddir/${script}.${eth0_net}"
  423.         else
  424.             if [ -f $lizarddir/${script} ]; then
  425.                 echo "$lizarddir/${script}"
  426.             else
  427.                 return 1
  428.             fi
  429.         fi
  430.     fi
  431.     return 0
  432. }
  433.  
  434.  
  435. Autoget_Lizard_Config()
  436. {
  437.     local eth0_ip=""
  438.     local eth0_mask=""
  439.     local nfs_server1_ip=""
  440.     local nfs_server1_path=""
  441.  
  442.     local eth0_net=""
  443.  
  444.     local lizarddir=$DIR_LIZARD
  445.     local rulesfile=$lizarddir/rules
  446.     local lizard_line
  447.     local lizard_dev=""
  448.  
  449.     local dummy
  450.  
  451.     # those are the filenames used in and parsed out of the rules file
  452.     local start_script
  453.     local profile
  454.     local xconfig
  455.     local pkgsel
  456.     local fsinfo
  457.     local finish_script
  458.  
  459.     # check whether we actually WANT a lizard install
  460.     lizard_line="`sed -n '/^lizard=/s/^lizard=//p' /tmp/cmdline`"
  461.     if [ -z "$lizard_line" ]; then
  462.         Debug "no lizard mode requested"
  463.         return 0
  464.     fi
  465.  
  466.     # check whether we overwrote the lizard location
  467.     if [ "$lizard_line" = "floppy" ]; then
  468.         lizard_dev="/dev/fd0H1440"
  469.     elif [ -n "`echo $lizard_line | sed -n '/:/p'`" ]; then
  470.         nfs_server1_ip="`echo $lizard_line | cut -d':' -f 1`"
  471.         nfs_server1_path="`echo $lizard_line | cut -d':' -f 2`"
  472.         # If NFS install then use defaults for lizard config location
  473.         if [ -n "$1" -a "$1" != "none" ]; then
  474.             eth0_ip="$1"
  475.             eth0_mask="$2"
  476.             eth0_net="`do_netcalc -n ${eth0_ip} ${eth0_mask}`"
  477.         fi 
  478.     elif [ "$lizard_line" = "auto" ]; then
  479.         # If NFS install then use defaults for lizard config location
  480.         if [ -n "$1" -a "$1" != "none" ]; then
  481.             eth0_ip="$1"
  482.             eth0_mask="$2"
  483.             nfs_server1_ip="$3"
  484.             nfs_server1_path="`dirname $4`/lizard"
  485.             eth0_net="`do_netcalc -n ${eth0_ip} ${eth0_mask}`"
  486.         fi 
  487.     else
  488.         lizard_dev="$lizard_line"
  489.     fi
  490.  
  491.     # look for lizard data
  492.     Debug "trying to mount lizard dir ... "
  493.     mkdir -p $lizarddir
  494.     if [ -n "$lizard_dev" ]; then
  495.         if [ "$lizard_dev" = "/dev/fd0H1440" ]; then
  496.             chvt 4
  497.             echo > /dev/tty4
  498.             echo -n "Please insert config floppy for LIZARD unattended install and press return." > /dev/tty4
  499.             read ans < /dev/tty4
  500.             chvt 7
  501.         fi
  502.         Debug "Trying mount -o ro -t ext2 $lizard_dev $lizarddir ..."
  503.         umount $lizard_dev > /dev/null 2>&1
  504.         mount -o ro -t ext2 $lizard_dev $lizarddir > /tmp/lizardmountout 2> /tmp/lizardmounterr || return 1
  505.     else
  506.         Debug "mount -o ro,bg,intr,nolock -t nfs ${nfs_server1_ip}:${nfs_server1_path} $lizarddir ..."
  507.         mount -o ro,bg,intr,nolock -t nfs ${nfs_server1_ip}:${nfs_server1_path} $lizarddir > /tmp/lizardmountout 2> /tmp/lizardmounterr || return 1
  508.     fi
  509.     if [ ! -f $rulesfile ]; then
  510.         Debug "no rules file found"
  511.         umount $lizarddir > /dev/null 2>&1
  512.         return 1
  513.     fi
  514.     # parse rules file for hostname entry
  515.     sed -n "/^hostname[     ]*${eth0_ip}[     ]*/p" $rulesfile > /tmp/rules
  516.     if [ -s /tmp/rules ]; then
  517.         Debug "found hostname match in rules file"
  518.     else
  519.         # parse rules file for network entry
  520.         sed -n "/^network[     ]*${eth0_net}[     ]*/p" $rulesfile > /tmp/rules
  521.         if [ -s /tmp/rules ]; then
  522.             Debug "found network match in rules file"
  523.         else
  524.             # parse rules file for floppy entry
  525.             sed -n "/^floppy[     ]*/p" $rulesfile > /tmp/rules
  526.             if [ -s /tmp/rules ]; then
  527.                 Debug "found floppy match in rules file"
  528.             else
  529.                 Debug "no match in rules file found"
  530.                 return 1
  531.             fi
  532.         fi
  533.     fi
  534.     read dummy dummy start_script profile xconfig pkgsel fsinfo finish_script < /tmp/rules
  535.     Debug "FILE_LIZARD_START=$start_script"
  536.     FILE_LIZARD_START="`Lizard_File_Glob $start_script $eth0_ip $eth0_net`"
  537.     Debug "actual FILE_LIZARD_START=$FILE_LIZARD_START"
  538.     Debug "FILE_LIZARD_PROFILE=$profile"
  539.     FILE_LIZARD_PROFILE="`Lizard_File_Glob $profile $eth0_ip $eth0_net`"
  540.     Debug "actual FILE_LIZARD_PROFILE=$FILE_LIZARD_PROFILE"
  541.     Debug "FILE_LIZARD_XCONFIG=$xconfig"
  542.     FILE_LIZARD_XCONFIG="`Lizard_File_Glob $xconfig $eth0_ip $eth0_net`"
  543.     Debug "actual FILE_LIZARD_XCONFIG=$FILE_LIZARD_XCONFIG"
  544.     Debug "FILE_LIZARD_PKGS=$pkgsel"
  545.     FILE_LIZARD_PKGS="`Lizard_File_Glob $pkgsel $eth0_ip $eth0_net`"
  546.     Debug "actual FILE_LIZARD_PKGS=$FILE_LIZARD_PKGS"
  547.     Debug "FILE_LIZARD_FSINFO=$fsinfo"
  548.     FILE_LIZARD_FSINFO="`Lizard_File_Glob $fsinfo $eth0_ip $eth0_net`"
  549.     Debug "actual FILE_LIZARD_FSINFO=$FILE_LIZARD_FSINFO"
  550.     Debug "FILE_LIZARD_FINISH=$finish_script"
  551.     FILE_LIZARD_FINISH="`Lizard_File_Glob $finish_script $eth0_ip $eth0_net`"
  552.     Debug "actual FILE_LIZARD_FINISH=$FILE_LIZARD_FINISH"
  553.     Breakpoint "after Autoget_Lizard_Config"
  554.     return 0
  555. }
  556.  
  557. Ask_Ether_Config()
  558. {
  559.     local bpf=/tmp/bootpc.out
  560.     local reply
  561.  
  562.     echo "Manual input of network information:" >> /dev/tty1
  563.     chvt 1
  564.  
  565.     echo -n "Enter the fully qualified hostname: "
  566.     read reply
  567.     echo "HOSTNAME=$reply" > $bpf
  568.  
  569.     echo -n "Enter the IP address : "
  570.     read reply
  571.     echo "IPADDR=$reply" >> $bpf
  572.  
  573.     echo -n "Enter the netmask : "
  574.     read reply
  575.     echo "NETMASK=$reply" >> $bpf
  576.  
  577.     echo -n "Enter the broadcast address : "
  578.     read reply
  579.     echo "BROADCAST=$reply" >> $bpf
  580.  
  581.     echo -n "Enter the network IP address : "
  582.     read reply
  583.     echo "NETWORK=$reply" >> $bpf
  584.  
  585.     echo -n "Enter the router IP address : "
  586.     read reply
  587.     echo "GATEWAYS=$reply" >> $bpf
  588.  
  589.     echo -n "Enter the DNS server IP address : "
  590.     read reply
  591.     echo "DNSSRVS=$reply" >> $bpf
  592.  
  593.     echo -n "Enter the NFS server IP address : "
  594.     read reply
  595.     echo "SERVER=$reply" >> $bpf
  596.  
  597.     echo -n "Enter the path to the root of CD 1 on the NFS server : "
  598.     read reply
  599.     echo "BOOTFILE=$reply" >> $bpf
  600.  
  601.     chvt 7
  602.     return 0
  603. }
  604.  
  605. Autoget_Ether_Config()
  606. {
  607.     local retval
  608.     local bpf=/tmp/bootpc.out
  609.     local fqhn=
  610.     local query_type=bootpc
  611.     local eth0_ip=
  612.     local eth0_mask=
  613.     local eth0_bcast=
  614.     local eth0_net=
  615.     local router1_ip=
  616.     local tftp_server1_ip=
  617.     local tftp_filename=
  618.     local dns_server1_ip=
  619.     local nfs_server1_ip=
  620.     local nfs_server1_path=
  621.  
  622.     if [ ! -x /bin/bootpc ]; then return 1 ; fi
  623.  
  624.     Do_fix_ePanic af_packet
  625.  
  626.     ifconfig eth0 down >> $FILE_LOG_DEBUG 2>&1
  627.     ifconfig lo down >> $FILE_LOG_DEBUG 2>&1
  628.  
  629.     ifconfig lo 127.0.0.1 netmask 255.0.0.0 broadcast 127.255.255.255 >> $FILE_LOG_DEBUG 2>&1
  630.     route add -net 127.0.0.0 netmask 255.0.0.0 dev lo >> $FILE_LOG_DEBUG 2>&1
  631.  
  632.     if [ -n "`sed -n '/^er=/p' /tmp/cmdline | fgrep asknet`" ]; then
  633.         query_type=asknet
  634.         echo "asking for network information..." >> $FILE_LOG_DEBUG
  635.         Ask_Ether_Config
  636.         retval=$?
  637.         Breakpoint "after asknet branch"
  638.     else
  639.         ifconfig eth0 0.0.0.0 >> $FILE_LOG_DEBUG 2>&1
  640.         echo "running bootpc..." >> $FILE_LOG_DEBUG
  641.         /bin/bootpc -t 6 | sed '/GATEWAYS=\"83.84/d' > $bpf 2>&1
  642.         retval=$?
  643.         Breakpoint "after bootpc request"
  644.     fi
  645.  
  646.     ifconfig eth0 down >> $FILE_LOG_DEBUG 2>&1
  647.     ifconfig lo down >> $FILE_LOG_DEBUG 2>&1
  648.  
  649.  
  650.     # the pcnet32 driver hangs in promiscous mode - reload it
  651.     # No longer true for 2.4 kernel. I hope. MM 20010115
  652.     #if [ -n "`cat /proc/modules | sed -n '/^pcnet32/p'`" ]; then
  653.     #    rmmod pcnet32
  654.     #    Do_Load_Module pcnet32
  655.     #    sleep 1
  656.     #fi
  657.  
  658.     if [ $retval -ne 0 ]; then
  659.         echo "$query_type returns with <$retval>" >> $FILE_LOG_DEBUG
  660.         Do_fix_ePanic bootpc || return 1
  661.         # return 1
  662.     fi
  663.  
  664.     if [ ! -s $bpf ]; then
  665.         echo "$query_type returns no output" >> $FILE_LOG_DEBUG
  666.         Do_fix_ePanic bootpc || return 1
  667.         # return 1
  668.     fi
  669.  
  670.     echo "$query_type returns:" >> $FILE_LOG_DEBUG
  671.     cat $bpf >> $FILE_LOG_DEBUG
  672.  
  673.     netdev="`get_val -f $bpf DEVICE`"
  674.     if [ -z "$netdev" ]; then
  675.         netdev="eth0"
  676.     fi
  677.     fqhn="`get_val -f $bpf HOSTNAME`"
  678.     eth0_ip="`get_val -f $bpf IPADDR`"
  679.     eth0_mask="`get_val -f $bpf NETMASK`"
  680.     eth0_bcast="`get_val -f $bpf BROADCAST`"
  681.     eth0_net="`get_val -f $bpf NETWORK`"
  682.     if [ -z "$eth0_net" ]; then
  683.         eth0_net="`do_netcalc -n $eth0_ip $eth0_mask`"
  684.     fi
  685.     # fix bootpc.out to only contain one value per entry
  686.     router1_ip="`get_val -f $bpf GATEWAYS | sed 's/ .*//'`"
  687.     set_val -f $bpf GATEWAYS "$router1_ip"
  688.     dns_server1_ip="`get_val -f $bpf DNSSRVS | sed 's/ .*//'`"
  689.     set_val -f $bpf DNSSRVS "$dns_server1_ip"
  690.     tftp_server1_ip="`get_val -f $bpf SERVER | sed 's/ .*//'`"
  691.     set_val -f $bpf SERVER "$tftp_server1_ip"
  692.     tftp_filename="`get_val -f $bpf BOOTFILE | sed 's/ .*//'`"
  693.     set_val -f $bpf BOOTFILE "$tftp_filename"
  694.  
  695.     echo "configuring network..." >> $FILE_LOG_DEBUG
  696.     ifconfig lo 127.0.0.1 netmask 255.0.0.0 broadcast 127.255.255.255 >> $FILE_LOG_DEBUG 2>&1
  697.     route add -net 127.0.0.0 netmask 255.0.0.0 dev lo >> $FILE_LOG_DEBUG 2>&1
  698.     ifconfig $netdev $eth0_ip netmask $eth0_mask broadcast $eth0_bcast >> $FILE_LOG_DEBUG 2>&1
  699.     route add -net $eth0_net netmask $eth0_mask dev $netdev >> $FILE_LOG_DEBUG 2>&1
  700.     route add default gw $router1_ip dev $netdev >> $FILE_LOG_DEBUG 2>&1
  701.     if [ "X$1" = "Xnomount" ]; then
  702.         return 0
  703.     fi
  704.     if [ -z "$tftp_server1_ip" -o -z "$tftp_filename" ]; then
  705.         return 1
  706.     fi
  707.     mount -o ro,bg,intr,nolock -t nfs ${tftp_server1_ip}:${tftp_filename} $DIR_SOURCE > /tmp/nfsmountout 2> /tmp/nfsmounterr || return 1
  708.  
  709.     Autoget_Lizard_Config ${eth0_ip} ${eth0_mask} ${tftp_server1_ip} ${tftp_filename} || return 1
  710.     return 0
  711. }
  712.  
  713.  
  714. Do_Load_Module()
  715. {
  716.     local ans=/tmp/ans
  717.     # local err=/tmp/err
  718.     local err=/dev/null
  719.     local modpath=/lib/modules/`uname -r`
  720.     local subpath=
  721.     local module=
  722.     local driver=
  723.     local modparam=
  724.     local modlist=/tmp/modules.initrd
  725.     local override_list=/tmp/modules.override
  726.     local override_module=false
  727.  
  728.     driver="$1"
  729.     shift 1
  730.     modparam="$@"
  731.  
  732. # lame little dependency hack - jwc
  733. if [ "$driver" = "usb-uhci" ]; then
  734.   Debug "${driver} requires usbcore."
  735.   echo "${driver} requires usbcore." >> $err
  736.   Do_Load_Module usbcore
  737. fi
  738.  
  739.     # check whether it's already loaded
  740.     /sbin/lsmod | sed -n "/^$driver/p" > $ans
  741.     if [ -s $ans ]; then
  742.         echo "$driver is already loaded" >> $err
  743.         return 0
  744.     fi
  745.  
  746.     # check whether it's available and prepare it for loading
  747.         for subpath in  kernel/drivers/block/ \
  748.                 kernel/drivers/cdrom \
  749.                 kernel/drivers/char/ \
  750.                 kernel/drivers/char/agp \
  751.                 kernel/drivers/char/joystick \
  752.                 kernel/drivers/char/rio \
  753.                 kernel/drivers/ide \
  754.                 kernel/drivers/net/ \
  755.                 kernel/drivers/parport \
  756.                 kernel/drivers/pnp \
  757.                 kernel/drivers/scsi \
  758.                 kernel/drivers/sound/ \
  759.                 kernel/drivers/sound/emu10k1 \
  760.                 kernel/drivers/usb/ \
  761.                 kernel/drivers/usb/serial \
  762.                 kernel/drivers/usb/storage \
  763.                 kernel/fs/ \
  764.                 kernel/net/sunrpc \
  765.                 pcmcia ; do
  766.         mkdir -p $modpath/$subpath
  767.         module="$modpath/$subpath/${driver}.o"
  768.         override_module=false
  769.         if [ -s /floppy/lib/modules/override/${subpath}/${driver}.o ]; then
  770.             echo "Found override for ${driver} (no gz)" >> $err
  771.             mkdir -p /override/$modpath/${subpath}
  772.             module="/override/$module"
  773.             cp -a /floppy/lib/modules/override/${subpath}/${driver}.o $module
  774.             override_module=true
  775.             break
  776.         elif [ -s /floppy/lib/modules/override/${subpath}/${driver}.o.gz ]; then
  777.             echo "Found override for ${driver} (gz)" >> $err
  778.             mkdir -p /override/$modpath/${subpath}
  779.             module="/override/$module"
  780.             gzip -dcf /floppy/lib/modules/override/${subpath}/${driver}.o.gz > $module
  781.             override_module=true
  782.             break
  783.         elif [ -s $module ]; then
  784.             break
  785.         elif [ -s $module.gz ]; then
  786.             gunzip $module.gz
  787.             break
  788.         elif [ -s /source/$module ]; then
  789.             module=/source/$module
  790.             break
  791.         elif [ -s /floppy/$module ]; then
  792.             module=/floppy/$module
  793.             break
  794.         elif [ -s /floppy/$module.gz ]; then
  795.             gzip -dcf /floppy/$module.gz > $module
  796.             break
  797.         fi
  798.         module=
  799.     done 
  800.  
  801.     if [ -z "$module" ]; then
  802.         echo "$driver not found anywhere" >> $err
  803.         return 1
  804.     fi 
  805.  
  806.     while [ 1 ]; do
  807.         Debug "trying <insmod $module $modparam> ... "
  808.         echo "trying <insmod $module $modparam> ... " >> $err
  809.         /sbin/insmod $module $modparam >> $err 2>&1 && break
  810.         /sbin/rmmod $driver >/dev/null 2>&1
  811.         Debug "insmod ${driver} failed. compressing module."
  812.         echo "insmod ${driver} failed. compressing module." >> $err
  813.         gzip -9 $module >/dev/null 2>&1
  814.         return 1
  815.     done
  816.     Debug "insmod ${driver} succeeded."
  817.     echo "insmod ${driver} succeeded." >> $err
  818.     echo "$driver" >> $modlist
  819.     if [ "$override_module" = "true" ]; then
  820.         Debug "override module tagged."
  821.         echo "$driver" >> $override_list
  822.         #Debug "override module saved (hardlinked) for later copy."
  823.         #mkdir /override/`dirname $module`
  824.         #ln -f $module /override/$module
  825.     fi
  826.     mkdir -p /etc/modules/options
  827.     if [ -n "$modparam" ]; then
  828.         echo "$modparam" > /etc/modules/options/$driver
  829.     else
  830.         rm -f /etc/modules/options/$driver
  831.     fi
  832.     return 0
  833. }
  834.  
  835.  
  836. Load_Default_Modules()
  837. {
  838.     local driver=
  839.  
  840.     for driver in $@ ; do
  841.         Do_Load_Module $driver ""
  842.     done
  843.     return 0
  844. }
  845.  
  846.  
  847. Do_Autoprobe()
  848. {
  849.     local what=
  850.     local how=
  851.  
  852.     # CD probelists (sbpcd takes too much time)
  853.     local cd_probelist_kernel="cdu31a mcd mcdx sbpcd aztcd sonycd535 gscd arcd bpcd bpmcd dscd eicd epcd kicd oicd pwcd cm206 optcd sjcd isp16"
  854.     # parallel port devices cause trouble :-(
  855.     local cd_probelist="cdu31a mcd mcdx aztcd sonycd535 gscd cm206 optcd sjcd isp16"
  856.     local cd_probelist_cautious="mcd gscd bpcd"
  857.  
  858.     # SCSI probelists (g_NCR5380 hangs)
  859.     local scsi_probelist_kernel="advansys BusLogic u14-34f ultrastor aha152x aha1542 aha1740 aic7xxx fdomain in2000 g_NCR5380 NCR53c406a qlogicfas pas16 seagate t128 dtc eata_pio wd7000 eata AM53C974 ppa"
  860.     local scsi_probelist="advansys BusLogic u14-34f ultrastor aha152x aha1542 aha1740 aic7xxx fdomain in2000 NCR53c406a qlogicfas pas16 seagate t128 dtc eata_pio wd7000 eata ppa"
  861.     local scsi_probelist_cautious="BusLogic aha1542 aic7xxx fdomain"
  862.  
  863.     # net probelists
  864.     local ether_probelist_kernel="de4x5 dgrs epic100 hp100 pcnet32 8139too 3c59x tulip e100 ac3200 smc-ultra32 at1700 smc-ultra smc9194 wd 3c503 hp hp-plus seeq8005 e2100 ne at1500 fmv18x eth16i 3c509 3c515 znet eexpress eepro depca ewrk3 apricot 3c501 3c507 3c505 de600 de620 ni52 ni65 lance"
  865.     # the at1500 is part of the e2100 ?
  866.     # the 3c501 is always misdetected :-(
  867.     # the seeq8005 and znet are not modularized :-(
  868.     # eepro and eexpress hang sometimes :-(
  869.     # parallel port devices cause trouble :-(
  870.     # tlan loads always :-(
  871.     local ether_probelist="de4x5 dgrs epic100 hp100 pcnet32 8139too 3c59x tulip e100 ac3200 smc-ultra32 at1700 smc-ultra smc9194 wd 3c503 hp hp-plus e2100 ne fmv18x eth16i 3c509 3c515 depca ewrk3 apricot 3c507 3c505 ni52 ni65 lance"
  872.     local ether_probelist_cautious="epic100 smc-ultra wd ne 3c509"
  873.  
  874.     local driver=
  875.     local modparam=
  876.     local retval=
  877.     local success=
  878.     local probelist_full=
  879.     local probelist_cautious=
  880.     local probelist_real=
  881.  
  882.     what="$1"
  883.     shift 1
  884.  
  885.     $CMD_BOOTER item $what
  886.  
  887.     case $what in
  888.     all)
  889.         # simulate full kernel autoprobing by load & test of all modules
  890.         # first we probe for CDROMs, then for SCSI hosts and last for ethernet
  891.         probelist_full="$cd_probelist $scsi_probelist $ether_probelist"
  892.         probelist_cautious="$cd_probelist_cautious $scsi_probelist_cautious $ether_probelist_cautious"
  893.         ;;
  894.     HDEVPCI)
  895.         if [ ! -f /proc/bus/pci/devices ] ; then
  896.             $CMD_BOOTER none
  897.             return 1
  898.         fi
  899.         cat /proc/bus/pci/devices|\
  900.         while read xid pciid rest ; do
  901.             :>/tmp/havedevice_$pciid
  902.         done
  903.         while read xid driver ; do
  904.             if [ x$xid = "xdriver" ] ; then
  905.                 curdriver=$driver
  906.             else
  907.                 if [ -f /tmp/havedevice_$xid ] ; then
  908.                     Do_Load_Module $curdriver
  909.                     retval=$?
  910.                     if [ $retval -eq 0 ]; then
  911.                         success=1
  912.                     fi
  913.                 fi
  914.             fi
  915.         done </etc/pcidrivers
  916.         if [ -n "$success" ] ; then
  917.             $CMD_BOOTER ok
  918.             return 0
  919.         else
  920.             $CMD_BOOTER skip
  921.             return 1
  922.         fi
  923.         ;;
  924.     HCDATAPI)
  925.         if [ -n "`cat /proc/ide/hd?/media 2> /dev/null | fgrep cdrom`" ]; then
  926.             $CMD_BOOTER ok
  927.             return 0
  928.         else
  929.             $CMD_BOOTER none
  930.             return 1
  931.         fi
  932.         ;;
  933.     CD|HCDOTHER)
  934.         # we skip that probe if we have either ATAPI or SCSI cdroms
  935.         # for speed issues
  936.         if [ -f /proc/sys/dev/cdrom/info ] ; then 
  937.             if [ -n "`cat /proc/sys/dev/cdrom/info|sed -e 's/drive name:.*[a-z]/HAVE_CDROM/g'|fgrep HAVE_CDROM`" ] ; then
  938.                 $CMD_BOOTER skip
  939.                 return 0
  940.             fi
  941.         fi
  942.         probelist_full="$cd_probelist"
  943.         probelist_cautious="$cd_probelist_cautious"
  944.         ;;
  945.     SCSI|HCDSCSI)
  946.         # we skip that probe if we already have one scsi hostadapter
  947.         if [ -n "`cat /proc/scsi/scsi|fgrep scsi0`" ] ; then
  948.             $CMD_BOOTER ok
  949.             return 1
  950.         fi
  951.         probelist_full="$scsi_probelist"
  952.         probelist_cautious="$scsi_probelist_cautious"
  953.         ;;
  954.     NET|HETHER)
  955.         # we skip that probe if we have already one net device
  956.         if [ -n "`sed -e '1,3d' /proc/net/dev`" ] ; then
  957.             $CMD_BOOTER ok
  958.             return 1
  959.         fi
  960.         probelist_full="$ether_probelist"
  961.         probelist_cautious="$ether_probelist_cautious"
  962.         ;;
  963.     esac
  964.  
  965.     if [ $# -gt 0 -a "$1" = "cautious" ]; then
  966.         probelist="$probelist_cautious"
  967.         all=0
  968.     elif [ $# -gt 0 -a "$1" = "nothing" ]; then
  969.         probelist=""
  970.         $CMD_BOOTER skip
  971.         return 0
  972.     elif [ $# -gt 0 -a "$1" = "query" ]; then
  973.         # one day we really want to launch an interactive mode here
  974.         # for now probe cautious in the network case, nothing in the
  975.         # other CDROMs case and everything in the SCSI hosts case
  976.         case $what in
  977.         NET|HETHER)
  978.             probelist="$probelist_cautious"
  979.             ;;
  980.         CD|HCDOTHER)
  981.             probelist=""
  982.             ;;
  983.         SCSI|HCDSCSI)
  984.             probelist="$probelist_full"
  985.             ;;
  986.         HCDATAPI)
  987.             :
  988.             # we will actually never get here. bad control flow :-(
  989.             ;;
  990.         esac
  991.     else
  992.         probelist="$probelist_full"
  993.     fi
  994.  
  995.  
  996.     Debug ":INFO_AUTOPROBE_RUNNING:"
  997.  
  998.     for driver in $probelist ; do
  999.         modparam=
  1000.         if [ "$driver" = "ne" ]; then
  1001.             # NE2000 cards need an io parameter. 0x300 is very common.
  1002.             modparam="io=0x300"
  1003.         fi
  1004.         Debug "probing ${driver} driver:"
  1005.         Do_Load_Module $driver $modparam
  1006.         retval=$?
  1007.         if [ $retval -eq 0 ]; then
  1008.             success=1
  1009.         fi
  1010.     done
  1011.     if [ -n "$success" ]; then
  1012.         $CMD_BOOTER ok
  1013.         return 0
  1014.     else
  1015.         $CMD_BOOTER none
  1016.         return 1
  1017.     fi
  1018. }
  1019.  
  1020.  
  1021. Check_Source_Valid()
  1022. {
  1023.     if [ -f $DIR_DATA/cd1 ]; then
  1024.         return 0
  1025.     else
  1026.         return 1
  1027.     fi
  1028. }
  1029.  
  1030.  
  1031. Check_Iso_Source_Valid()
  1032. # jwc - check for /redmondlinux.iso in the root of a linux partition
  1033. {
  1034.     if [ -f $DIR_ISO_FILE ]; then
  1035.         return 0
  1036.     else
  1037.         return 1
  1038.     fi
  1039. }
  1040. #jwc
  1041.  
  1042.  
  1043. Failsafe_CD_Mount()
  1044. {
  1045.     local dev="$1"
  1046.     local dir="$2"
  1047.     local short_dev
  1048.  
  1049.     # first try a normal mount
  1050.     mount -r -t iso9660 $dev $dir > /dev/null 2>&1 
  1051.     Check_Source_Valid && return 0
  1052.     umount $dir > /dev/null 2>&1
  1053.  
  1054.     # nothing can be done on non-ATAPI cdrom failure
  1055.     if [ -z "`echo $dev | fgrep '/dev/hd'`" ]; then
  1056.         return 1
  1057.     fi
  1058.  
  1059.     # for ATAPI cdroms we can disble dma and try again as a fallback
  1060.     short_dev="`echo $dev | cut -c6-`"
  1061.     Debug "Disabling DMA for $short_dev and trying again ..."
  1062.     echo "using_dma:0" > /proc/ide/${short_dev}/settings
  1063.     mount -r -t iso9660 $dev $dir > /dev/null 2>&1 
  1064.     Check_Source_Valid && return 0
  1065.  
  1066.     # Hmm, nothing can be done :-(
  1067.     umount $dir > /dev/null 2>&1
  1068.     return 1
  1069. }
  1070.  
  1071.  
  1072. Do_Mount_Source()
  1073. {
  1074.     local devs
  1075.     local dev
  1076.     local ans
  1077.  
  1078.     Breakpoint "Do_Mount_Source"
  1079.  
  1080.     $CMD_BOOTER add_menu "BLANK2"
  1081.     $CMD_BOOTER add_menu "T2 Automatic install source detection:"
  1082.     $CMD_BOOTER list "L2 Mount"
  1083.     $CMD_BOOTER add "MCD Installation from CDROM"
  1084.     $CMD_BOOTER add "MNFS Installation over NFS"
  1085.     $CMD_BOOTER add "MDISK Installation from harddisk"
  1086.     $CMD_BOOTER end
  1087.     $CMD_BOOTER show
  1088.     $CMD_BOOTER activate L2
  1089.  
  1090.     # FIXME: for now the order of probing is fixed (CDROM, NFS, SMB, disk)
  1091.     #        and we stop probing when we found the first valid source
  1092.  
  1093.     mkdir -p $DIR_SOURCE
  1094.     $CMD_BOOTER item MCD
  1095.     sysinfo --var --cdrom > /dev/null 2> /tmp/cdroms
  1096.     devs="`cut -d':' -f 2 /tmp/cdroms`"
  1097.  
  1098.     # shake the ethernet interface to wake up ;-)
  1099.     # FIXME: should we do this for all ifs? or just get rid of it?
  1100.     if [ -n "`sed -e '1,3d' /proc/net/dev`" ]; then
  1101.         ifconfig eth0 down >> $FILE_LOG_DEBUG 2>&1
  1102.         ifconfig lo down >> $FILE_LOG_DEBUG 2>&1
  1103.         ifconfig lo 127.0.0.1 netmask 255.0.0.0 broadcast 127.255.255.255 >> $FILE_LOG_DEBUG 2>&1
  1104.         route add -net 127.0.0.0 netmask 255.0.0.0 dev lo >> $FILE_LOG_DEBUG 2>&1
  1105.         ifconfig eth0 0.0.0.0 >> $FILE_LOG_DEBUG 2>&1
  1106.         ifconfig eth0 down >> $FILE_LOG_DEBUG 2>&1
  1107.         ifconfig lo down >> $FILE_LOG_DEBUG 2>&1
  1108.     fi
  1109.  
  1110.     if [ -n "$devs" ]; then
  1111.         Debug "Checking for CDROM source"
  1112.         for dev in $devs ; do
  1113.             Failsafe_CD_Mount $dev $DIR_SOURCE
  1114.             if [ $? -eq 0 ]; then
  1115.                 if [ -n "`sed -e '1,3d' /proc/net/dev`" ]; then
  1116.                     if [ -z "`sed -n '/^er=/p' /tmp/cmdline | fgrep cautious`" ]; then
  1117.                         Debug "Checking network without mount"
  1118.                         Autoget_Ether_Config nomount
  1119.                     fi
  1120.                 fi
  1121.                 Autoget_Lizard_Config none none none none || continue
  1122.                 $CMD_BOOTER ok
  1123.                 $CMD_BOOTER item MNFS
  1124.                 $CMD_BOOTER skip
  1125.                 $CMD_BOOTER item MDISK
  1126.                 $CMD_BOOTER skip
  1127.                 return 0
  1128.             fi
  1129.             umount $DIR_SOURCE > /dev/null 2>&1
  1130.         done
  1131.         $CMD_BOOTER skip
  1132.     else
  1133.         $CMD_BOOTER skip
  1134.     fi
  1135.     $CMD_BOOTER item MNFS
  1136.     # FIXME: should do it over all Ethernet cards, not only eth0
  1137.     if [ -n "`sed -e '1,3d' /proc/net/dev`" ]; then
  1138.         Debug "Checking for network source"
  1139.         Autoget_Ether_Config
  1140.         if [ $? -eq 0 ]; then
  1141.             Check_Source_Valid
  1142.             if [ $? -eq 0 ]; then
  1143.                 $CMD_BOOTER ok
  1144.                 $CMD_BOOTER item MDISK
  1145.                 $CMD_BOOTER skip
  1146.                 return 0
  1147.             fi
  1148.             umount $DIR_SOURCE > /dev/null 2>&1
  1149.             umount $DIR_LIZARD > /dev/null 2>&1
  1150.         fi
  1151.     fi
  1152.     $CMD_BOOTER skip
  1153.     $CMD_BOOTER item MDISK
  1154.     # try Linux partitions first
  1155.     devs="`sysinfo --tag -C Linux --partition`"
  1156.     if [ -n "$devs" ]; then
  1157.         Debug "Checking for Linux partition source"
  1158.         Debug "... and also redmondlinux.iso source" # jwc
  1159.         for dev in $devs ; do
  1160.             mount -r -t ext2 $dev $DIR_SOURCE > /dev/null 2>&1 
  1161.             Check_Source_Valid
  1162.             if [ $? -eq 0 ]; then
  1163.                 Autoget_Lizard_Config none none none none || continue
  1164.                 $CMD_BOOTER ok
  1165.                 return 0
  1166.             fi
  1167.             umount $DIR_SOURCE > /dev/null 2>&1
  1168.                         # jwc - check .iso images also
  1169.                         mount -r -t ext2 $dev $DIR_SOURCE_TMP > /dev/null 2>&1
  1170.                         Check_Iso_Source_Valid
  1171.                         if [ $? -eq 0 ]; then
  1172.                                 mount -r -t iso9660 -o loop=/dev/loop0 $DIR_ISO_FILE $DIR_SOURCE > /dev/null 2>&1
  1173.                                 Autoget_Lizard_Config none none none none || continue
  1174.                                 $CMD_BOOTER ok
  1175.                                 return 0
  1176.                         fi
  1177.                         umount $DIR_SOURCE_TMP > /dev/null 2>&1
  1178.                         # jwc - end check .iso images
  1179.         done
  1180.     fi    
  1181.  
  1182.     # finally try DOS partitions
  1183.     devs="`sysinfo --tag -C DOS --partition`"
  1184.     if [ -n "$devs" ]; then
  1185.         Debug "Checking for DOS partition source"
  1186.         for dev in $devs ; do
  1187.             mount -r -t vfat $dev $DIR_SOURCE > /dev/null 2>&1 
  1188.             Check_Source_Valid
  1189.             if [ $? -eq 0 ]; then
  1190.                 Autoget_Lizard_Config none none none none || continue
  1191.                 $CMD_BOOTER ok
  1192.                 return 0
  1193.             fi
  1194.             umount $DIR_SOURCE > /dev/null 2>&1
  1195.         done
  1196.     fi    
  1197.     $CMD_BOOTER skip
  1198.     $CMD_BOOTER complete L2
  1199.  
  1200.     return 1
  1201. }
  1202.  
  1203.  
  1204. Do_Extended_Autoprobe()
  1205. {
  1206.     local module
  1207.  
  1208.     # isapnp is now under misc, but without uname -r
  1209.     if [ -r /lib/modules/misc/isapnp.o ]; then
  1210.         insmod isapnp
  1211.     fi
  1212.  
  1213.     # load more default modules now that the install source is mounted
  1214.     Load_Default_Modules isapnp fat msdos vfat umsdos scsi_mod
  1215.  
  1216.     # use hwprobe to write /etc/modules.conf
  1217.     if [ -x /sbin/hwprobe ]; then
  1218.         Breakpoint "before hwprobe"
  1219.         if [ -f /etc/hwprobe.config ]; then
  1220.             /sbin/hwprobe /etc/hwprobe.config
  1221.         else
  1222.             /sbin/hwprobe
  1223.         fi
  1224.     fi
  1225.  
  1226.     # load modules according to the generated default file
  1227.     if [ -s /etc/modules/default ]; then
  1228.         Breakpoint "before default module loading (hwprobe based)"
  1229.         for module in `cat /etc/modules/default | sed '/^#/d'` ; do
  1230.             if [ -z "`sed -n "/^$module /p" /proc/modules`" ]; then
  1231.                 echo "Trying modprobe $module (forced by /etc/modules/default)" > $FILE_LOG_DEBUG 2>&1
  1232.                 modprobe $module > $FILE_LOG_DEBUG 2>&1
  1233.             else
  1234.                 echo "Skipping modprobe $module (forced by /etc/modules/default but already loaded)" > $FILE_LOG_DEBUG 2>&1
  1235.             fi
  1236.         done
  1237.     fi
  1238.     Load_Default_Modules sd sd_mod sr_mod sg
  1239.     if fgrep usbdevfs /proc/filesystems >/dev/null ; then
  1240.         mount -t usbdevfs none /proc/bus/usb
  1241.         echo "Trying to start USB hotplugd" > $FILE_LOG_DEBUG 2>&1
  1242.         if [ -x /usr/sbin/hotplugd ]; then
  1243.             /usr/sbin/hotplugd
  1244.         fi
  1245.     fi
  1246.  
  1247.     return 0
  1248. }
  1249.  
  1250.  
  1251. Prepare_lisa()
  1252. {
  1253.     Breakpoint "Prepare_lisa"
  1254.     if [ -x /bin/lisaprep ]; then
  1255.         /bin/lisaprep || return 1
  1256.         return 0
  1257.     elif [ -x $DIR_LIVE/lisa/bin/lisaprep ]; then
  1258.         $DIR_LIVE/lisa/bin/lisaprep || return 1
  1259.         return 0
  1260.     else
  1261.         return 1
  1262.     fi
  1263.     return 0
  1264. }
  1265.  
  1266.  
  1267. Prepare_lizard()
  1268. {
  1269.     Breakpoint "Prepare_lizard"
  1270.  
  1271.     # minimal network to make sure sockets work
  1272.     ifconfig lo down >> $FILE_LOG_DEBUG 2>&1
  1273.     ifconfig lo 127.0.0.1 netmask 255.0.0.0 broadcast 127.255.255.255 >> $FILE_LOG_DEBUG 2>&1
  1274.     route add -net 127.0.0.0 netmask 255.0.0.0 dev lo >> $FILE_LOG_DEBUG 2>&1
  1275.     # unpack live filesystem
  1276.     if [ -x `dirname $DIR_LIVE`/clive/uncramfs ]; then
  1277.         Breakpoint "before uncramfs"
  1278.         `dirname $DIR_LIVE`/clive/uncramfs
  1279.     fi
  1280.  
  1281.     # prepare install environment
  1282.     if [ -x $DIR_LIVE/activate ]; then
  1283.         Breakpoint "before activate"
  1284.         $DIR_LIVE/activate # || return 1
  1285.         Do_fix_ePanic lsmod
  1286.     else
  1287.         return 1
  1288.     fi
  1289.  
  1290.     if [ -z "`sed -n '/^er=/p' /tmp/cmdline | fgrep cautious`" ]; then
  1291.         # we have access to all modules through the live filesystem
  1292.         # so we can run an extended autoprobe
  1293.         Do_Extended_Autoprobe
  1294.     fi
  1295.  
  1296.     # add all needed disk devices
  1297.     Make_DISK_Devices
  1298.  
  1299.     return 0
  1300. }
  1301.  
  1302.  
  1303. Run_lisa_install()
  1304. {
  1305.     local retval
  1306.     local tgtdev
  1307.  
  1308.     Breakpoint "Run_lisa_install"
  1309.     chvt 1
  1310.     # try to autodetect Monochrome terminals
  1311.     sysinfo --video | fgrep Mono > /dev/null
  1312.     if [ $? -eq 0 ]; then
  1313.         export TERM=linux-mono
  1314.     else
  1315.         export TERM=linux
  1316.     fi
  1317.     if [ -n "`sed -n '/^er=/p' /tmp/cmdline | fgrep expert`" ]; then
  1318.         set_val MODE_USER expert
  1319.         export LOGNAME="expert"
  1320.         expert_param='--expert'
  1321.     else
  1322.         set_val MODE_USER newbie
  1323.         export LOGNAME="install"
  1324.         expert_param='--newbie'
  1325.     fi
  1326.     prep_use LISA
  1327.     Debug "lisa $expert_param --first ... "
  1328.     lisa $expert_param --first
  1329.     retval=$?
  1330.     echo "Debug: lisa finished with return val $retval" > /dev/tty4
  1331.     chvt 7
  1332.     if [ $retval -eq 0 ]; then
  1333.         # now remount the target root from /root to /mnt/root
  1334.         tgtdev="`mount | fgrep ' on /root ' | cut -d' ' -f 1`"
  1335.         umount $tgtdev
  1336.         mount -t ext2 $tgtdev /mnt/root
  1337.         Retrieve_sysinfo
  1338.         $CMD_BOOTER ok
  1339.     else
  1340.         $CMD_BOOTER fail
  1341.         sleep 1
  1342.     fi
  1343.     return $retval
  1344. }
  1345.  
  1346.  
  1347. Run_lizard_interactive()
  1348. {
  1349.     local retval
  1350.     local display_param=""
  1351.     local fb_param=""
  1352.     local expert_param=""
  1353.     local lizard_param=""
  1354.     local demo_param=""
  1355.     local cautious_params=""
  1356.  
  1357.     Breakpoint "Run_lizard_interactive"
  1358.  
  1359.     if [ -d /lizard/. ] ; then
  1360.         cd /lizard/
  1361.     else
  1362.         cd $DIR_LIVE_LIZARD
  1363.     fi
  1364.  
  1365.     # allow to remote-set the display
  1366.     display_param="`sed -n '/^display=/p' /tmp/cmdline | cut -d'=' -f 2-`"
  1367.     if [ -n "$display_param" ]; then
  1368.         display_param="-display $display_param"
  1369.     fi
  1370.     # if the kernel runs in frame buffer than we should use FB X in LIZARD
  1371.     fb_param="`fgrep -x 'vga=785' /tmp/cmdline`"
  1372.     if [ -n "$fb_param" ]; then
  1373.         fb_param="-server XF86_FBDev"
  1374.     fi
  1375.     # set -noskip if we run in expert mode
  1376.     if [ -n "`sed -n '/^er=/p' /tmp/cmdline | fgrep expert`" ]; then
  1377.         expert_param='-noskip'
  1378.     fi
  1379.     if [ -n "`sed -n '/^er=/p' /tmp/cmdline | fgrep cautious`" ]; then
  1380.         cautious_params='-nosound -nomouseprobe -nonetprobe'
  1381.     fi
  1382.     lizard_param="`sed -n '/lz=/p' /tmp/cmdline | cut -d'=' -f 2- | sed 's/[=,]/ /g'`"
  1383.     if [ -n "`sed -n '/^er=/p' /tmp/cmdline | fgrep demo`" ]; then
  1384.         demo_param='-demo'
  1385.     fi
  1386.     Debug "./lizard $display_param $fb_param $expert_param $cautious_params $lizard_param $demo_param ... "
  1387.     ./lizard $display_param $fb_param $expert_param $cautious_params $lizard_param $demo_param 2> /dev/tty4
  1388.     retval=$?
  1389.     echo "Debug: lizard finished with return val $retval" > /dev/tty4
  1390.  
  1391.     chvt 7
  1392.  
  1393.     # FIXME: dirty hack: we assume ok until Qt segfault bug is found
  1394.     #retval=0
  1395.  
  1396.     if [ $retval -eq 0 ]; then
  1397.         $CMD_BOOTER ok
  1398.     else
  1399.         $CMD_BOOTER fail
  1400.         sleep 1
  1401.     fi
  1402.     return $retval
  1403. }
  1404.  
  1405.  
  1406. Set_Val()
  1407. {
  1408.     local f=$DIR_TARGET/etc/system.cnf
  1409.  
  1410.     set_val -f $f $1 "$2"
  1411. }
  1412.  
  1413.  
  1414. Get_root()
  1415. {
  1416.     local dev
  1417.     local major
  1418.     local minor
  1419.  
  1420.     dev="`sed -n '/ \/mnt\/root /p' /proc/mounts | cut -d' ' -f 1`"
  1421.     echo "Root device is detected as $dev" > /dev/tty4
  1422.     if [ -z "$dev" ]; then
  1423.         # Hmmm, it seems lizard did not finish it's job :-(
  1424.         # give them something that doesn't hurt us and will
  1425.         # let us land safely. The kernel will remount the
  1426.         # ramdisk and call /bin/sh (as we have no /sbin/init)
  1427.         Panic "Ooops, no valid root could be found! Lizard aborted?"
  1428.         Panic "Preparing for an emergency landing ..."
  1429.         dev=/dev/ram
  1430.     fi
  1431.     major="`ls -l $dev | cut -c 35-36 | sed 's/ //g'`"
  1432.     minor="`ls -l $dev | cut -c 40-41 | sed 's/ //g'`"
  1433.  
  1434.     case $1 in
  1435.     dev)
  1436.         echo "$dev"
  1437.         return 0
  1438.         ;;
  1439.     id)
  1440.         echo "$dev"
  1441.         return 0
  1442.         ;;
  1443.     esac
  1444.     return 0
  1445. }
  1446.  
  1447.  
  1448. Dec2Hex()
  1449. {
  1450.     local n1=`do_calc $1 / 16`
  1451.     local t1=`do_calc $n1 \* 16`
  1452.     local n2=`do_calc $1 - $t1`
  1453.     local i=
  1454.     local r=""
  1455.   
  1456.     if [ $n1 -eq 0 ]; then
  1457.         n1=0
  1458.     fi
  1459.  
  1460.     for i in $n1 $n2; do
  1461.         if [ $i -lt 10 ]; then
  1462.             r="${r}$i"
  1463.         else
  1464.             case "$i" in
  1465.             10) r="${r}a" ;;
  1466.             11) r="${r}b" ;;
  1467.             12) r="${r}c" ;;
  1468.             13) r="${r}d" ;;
  1469.             14) r="${r}e" ;;
  1470.             15) r="${r}f" ;;
  1471.             esac
  1472.         fi
  1473.     done
  1474.   
  1475.     echo "$r"
  1476.     return 0
  1477. }
  1478.  
  1479.  
  1480. Dev2Hex()
  1481. {
  1482.     local root_dev=
  1483.     local driver=
  1484.     local disk=
  1485.     local base=
  1486.     local partition=
  1487.     local major=
  1488.     local minor=
  1489.     local high=
  1490.     local low=
  1491.     local bios_id=
  1492.  
  1493.     root_dev="`echo $1 | sed 's/^\/dev\///'`"
  1494.     driver="`echo $root_dev | cut -c 1-2`"
  1495.  
  1496.     while read major minor blocks name; do
  1497.         if [ "$root_dev" = "$name" ]; then
  1498.             minor="`Dec2Hex $minor`"
  1499.             major="`Dec2Hex $major`"
  1500.             echo "0x${major}${minor}"
  1501.             return 0
  1502.         fi
  1503.     done < /proc/partitions
  1504.  
  1505.     # both parts of the code below needs to be cross checked.
  1506.     if [ "$driver" = "rd" ]; then
  1507.         driver="`echo $root_dev | cut -c 1-5`"
  1508.         disk="`echo $root_dev | cut -c 7-7`"
  1509.         partition="`echo $root_dev | cut -c 9-`"
  1510.         base=8
  1511.     elif [ "$driver" = "id" ]; then
  1512.         driver="`echo $root_dev | cut -c 1-6`"
  1513.         disk="`echo $root_dev | cut -c 8-8`"
  1514.         partition="`echo $root_dev | cut -c 10-`"
  1515.         base=16
  1516.     elif [ "$driver" = "cc" ]; then
  1517.         driver="`echo $root_dev | cut -c 1-8`"
  1518.         disk="`echo $root_dev | cut -c 10-10`"
  1519.         partition="`echo $root_dev | cut -c 12-`"
  1520.         base=16
  1521.     else
  1522.         disk="`echo $root_dev | cut -c 3-3`"
  1523.         partition="`echo $root_dev | cut -c 4-`"
  1524.         base=64
  1525.     fi
  1526.  
  1527.     case $driver in
  1528.     hd)
  1529.         major=22
  1530.         if [ "$disk" = "a" -o "$disk" = "b" ]; then major=3
  1531.         elif [ "$disk" = "c" -o "$disk" = "d" ]; then major=22
  1532.         elif [ "$disk" = "e" -o "$disk" = "f" ]; then major=33
  1533.         elif [ "$disk" = "g" -o "$disk" = "h" ]; then major=34
  1534.         fi
  1535.         ;;
  1536.     ida/c0) major=72 ;;
  1537.     cciss/c0) major=104 ;;
  1538.     rd/c0) major=48 ;;
  1539.     sd)
  1540.         base=16
  1541.         major=8
  1542.         ;;
  1543.     xd) major=13 ;;
  1544.     esac
  1545.  
  1546.     high="`Dec2Hex $major`"
  1547.  
  1548.     case $disk in
  1549.     a|0) minor=0 ;;
  1550.     b|1) minor=1 ;;
  1551.     c|2)
  1552.         if [ "$driver" = "hd" ]; then
  1553.             minor=0
  1554.         else
  1555.             minor=2
  1556.         fi
  1557.         ;;
  1558.     d|3)
  1559.         if [ "$driver" = "hd" ]; then
  1560.             minor=1
  1561.         else
  1562.             minor=3
  1563.         fi
  1564.         ;;
  1565.     e|4) 
  1566.         if [ "$driver" = "hd" ]; then
  1567.             minor=0
  1568.         else
  1569.             minor=4
  1570.         fi
  1571.         ;;
  1572.     f|5) 
  1573.         if [ "$driver" = "hd" ]; then
  1574.             minor=1
  1575.         else
  1576.             minor=5
  1577.         fi
  1578.         ;;
  1579.     g|6)
  1580.         if [ "$driver" = "hd" ]; then
  1581.             minor=0
  1582.         else
  1583.             minor=6
  1584.         fi
  1585.         ;;
  1586.     h|7)
  1587.         if [ "$driver" = "hd" ]; then
  1588.             minor=1
  1589.         else
  1590.             minor=7
  1591.         fi
  1592.         ;;
  1593.     esac
  1594.  
  1595.     low="`do_calc $minor \* $base`"
  1596.     low="`do_calc $low \+ $partition`"
  1597.     low="`Dec2Hex $low`"
  1598.  
  1599.     echo "0x${high}${low}"
  1600.     return 0
  1601. }
  1602.  
  1603.  
  1604. # retrieve the real root device either from the cmdline or the mounted target
  1605. Set_real_root_dev()
  1606. {
  1607.     local dev
  1608.     local id
  1609.     local f=/proc/sys/kernel/real-root-dev
  1610.  
  1611.     if [ $# -eq 1 -a "$1" = "cmdline" ]; then
  1612.         dev="`sed -n '/^root=/p' /tmp/cmdline | cut -d'=' -f 2`"
  1613.         if [ -n "`echo $dev | fgrep dev`" ]; then
  1614.             id="`Dev2Hex $dev`"
  1615.         else
  1616.             id="0x$dev"
  1617.         fi
  1618.     else
  1619.         dev="`Get_root dev`"
  1620.         id="`Dev2Hex $dev`"
  1621.     fi
  1622.     echo "$id" > $f
  1623.     return 0
  1624. }
  1625.  
  1626.  
  1627. Fix_etc_fstab()
  1628. {
  1629.     local f=$DIR_TARGET/etc/fstab
  1630.     local dev=
  1631.  
  1632.     # try to derive the CDROM that we installed from or the first one
  1633.     if [ -n "`fgrep '/mnt/install' /proc/mounts | fgrep 'iso9660'`" ]; then
  1634.         dev="`fgrep '/mnt/install' /proc/mounts | cut -d' ' -f 1`"
  1635.     else
  1636.         sysinfo --var --cdrom > /dev/null 2> /tmp/cdroms
  1637.         dev="`cut -d':' -f 2 /tmp/cdroms | sed '2,$d'`"
  1638.     fi
  1639.  
  1640.     # add proc entry to fstab
  1641.     mkdir -p $DIR_TARGET/proc
  1642.     if [ -z "`sed -n '/^\/proc/p' $DIR_TARGET/etc/fstab`" ]; then
  1643.         echo "/proc /proc proc defaults 0 0" >> $f
  1644.     fi
  1645.  
  1646.     # add devpts entry to fstab (if missing)
  1647.     if [ -z "`sed -n '/^devpts/p' $DIR_TARGET/etc/fstab`" ]; then
  1648.         echo "devpts /dev/pts devpts gid=5,mode=620 0 0" >> $f
  1649.     fi
  1650.  
  1651.     # add floppy entry to fstab
  1652.     mkdir -p $DIR_TARGET/mnt/floppy
  1653.     if [ -z "`sed -n '/^\/dev\/fd0/p' $DIR_TARGET/etc/fstab`" ]; then
  1654.         echo "/dev/fd0 /mnt/floppy auto defaults,user,noauto 0 0" >> $f
  1655.     fi
  1656.  
  1657.     # add cdrom entry to fstab
  1658.     mkdir -p $DIR_TARGET/mnt/cdrom
  1659.     if [ -n "$dev" ]; then
  1660.         rm -f $DIR_TARGET/dev/cdrom
  1661.         ln -s $dev $DIR_TARGET/dev/cdrom
  1662.         if [ -z "`sed -n '/\/mnt\/cdrom/p' $DIR_TARGET/etc/fstab`" ]; then
  1663.             echo "$dev /mnt/cdrom iso9660 ro,user,noauto,exec 0 0" >> $f
  1664.         fi
  1665.     fi
  1666.     return 0
  1667. }
  1668.  
  1669.  
  1670. Fix_keyboard()
  1671. {
  1672.     local f=$DIR_TARGET/etc/sysconfig/keyboard
  1673.  
  1674.     # source what lizard dumped into /tmp/keyboard
  1675.     if [ -f /tmp/keyboard ]; then
  1676.         . /tmp/keyboard
  1677.         CONF_KEYBOARD_MAP="us.map"
  1678.     else
  1679.         CONF_KEYBOARD_MODEL="pc101"
  1680.         CONF_KEYBOARD_LAYOUT="us"
  1681.         CONF_KEYBOARD_MAP="us.map"
  1682.     fi
  1683.  
  1684.     # map X keyboard names to kernel keyboard names
  1685.     # FIXME: fill in missing entries (currently fallback to us.map)
  1686.     case $CONF_KEYBOARD_LAYOUT in
  1687.     us)
  1688.         # U.S. English
  1689.         CONF_KEYBOARD_MAP="us.map"
  1690.         ;;
  1691.     be)
  1692.         # Belgian
  1693.         ;;
  1694.     bg)
  1695.         # Bulgarian
  1696.         ;;
  1697.     ca)
  1698.         # Canadian
  1699.         ;;
  1700.     cs)
  1701.         # Czechoslovakian
  1702.         ;;
  1703.     de_CH)
  1704.         # Swiss German
  1705.         ;;
  1706.     dk)
  1707.         # Danish
  1708.         ;;
  1709.     es)
  1710.         # Spanish
  1711.         CONF_KEYBOARD_MAP="es.map"
  1712.         ;;
  1713.     de)
  1714.         # German
  1715.         CONF_KEYBOARD_MAP="de-latin1-nodeadkeys.map"
  1716.         ;;
  1717. # ash is unhappy with this :-(
  1718. #    fi)
  1719. #        # Finish
  1720. #        CONF_KEYBOARD_MAP="fi-latin1.map"
  1721. #        ;;
  1722.     fr)
  1723.         # French
  1724.         CONF_KEYBOARD_MAP="fr-latin1.map"
  1725.         ;;
  1726.     sf)
  1727.         # Swiss French
  1728.         ;;
  1729.     gb)
  1730.         # United Kingdom
  1731.         CONF_KEYBOARD_MAP="uk.map"
  1732.         ;;
  1733.     hg)
  1734.         # Hungarian 
  1735.         ;;
  1736.     it)
  1737.         # Italian
  1738.         CONF_KEYBOARD_MAP="it.map"
  1739.         ;;
  1740.     jp)
  1741.         # Japanese
  1742.         ;;
  1743.     no)
  1744.         # Norwegian
  1745.         ;;
  1746.     pl)
  1747.         # Polish
  1748.         ;;
  1749.     pt)
  1750.         # Portugese
  1751.         ;;
  1752.     ru)
  1753.         # Russian
  1754.         ;;
  1755.     se)
  1756.         # Swedish
  1757.         ;;
  1758.     th)
  1759.         # Thai
  1760.         ;;
  1761.     esac
  1762.  
  1763.     Set_Val CONF_KEYBOARD_MAP "$CONF_KEYBOARD_MAP"
  1764.     mkdir -p $DIR_TARGET/etc/sysconfig
  1765.     echo "KEYTABLE=$CONF_KEYBOARD_MAP" > $f
  1766.     return 0
  1767. }
  1768.  
  1769.  
  1770. Fix_timezone()
  1771. {
  1772.     local f=$DIR_TARGET/etc/sysconfig/clock
  1773.  
  1774.     # source what lizard dumped into /tmp/clock
  1775.     if [ -f /tmp/clock ]; then
  1776.         . /tmp/clock
  1777.     else
  1778.         CONF_TIMEZONE="GMT"
  1779.         CONF_KERNTZ_FLAG="u"
  1780.     fi
  1781.  
  1782.     CLOCKMODE=GMT
  1783.     case $CONF_KERNTZ_FLAG in
  1784.     u)
  1785.         CLOCKMODE=GMT
  1786.         ;;
  1787.     l)
  1788.         CLOCKMODE=LOCAL
  1789.         ;;
  1790.     esac
  1791.  
  1792.     # set /etc/system.cnf
  1793.     Set_Val CONF_TIMEZONE "$CONF_TIMEZONE"
  1794.     Set_Val CONF_KERNTZ_FLAG "$CONF_KERNTZ_FLAG"
  1795.  
  1796.     # create /etc/sysconfig/clock
  1797.     mkdir -p $DIR_TARGET/etc/sysconfig
  1798.     echo "CLOCKMODE=$CLOCKMODE" > $f
  1799.  
  1800.     # create /etc/localtime
  1801.     ln -sf /usr/share/zoneinfo/${CONF_TIMEZONE} $DIR_TARGET/etc/localtime
  1802.     return 0
  1803. }
  1804.  
  1805.  
  1806. Fix_mouse()
  1807. {
  1808.     local MOUSETYPE=ps2
  1809.     local PROTO=ps2
  1810.     local XEMU3=no
  1811.     local DRIVER=psaux
  1812.  
  1813.     # source what lizard dumped into /tmp/mouse
  1814.     if [ -f /tmp/mouse ]; then
  1815.         . /tmp/mouse
  1816.     else
  1817.         CONF_MOUSE1_TYPE="PS2"
  1818.         CONF_MOUSE1_X_TYPE="ps/2"
  1819.         CONF_MOUSE1_DEV="/dev/psaux"
  1820.         CONF_MOUSE1_BUTTONS="3"
  1821.     fi
  1822.  
  1823.     case $CONF_MOUSE1_X_TYPE in
  1824.     MouseManPlusPS/2|IMPS/2|ThinkingMousePS/2|GlidePointPS/2|NetMousePS/2|NetScrollPS/2|PS/2|ps/2)
  1825.         CONF_MOUSE1_TYPE="PS2"
  1826.         CONF_MOUSE1_X_TYPE="ps/2"
  1827.         CONF_MOUSE1_DEV="/dev/psaux"
  1828.         MOUSETYPE=ps2
  1829.         PROTO=ps2
  1830.         DRIVER=psaux
  1831.         ;;
  1832.     Logitech|logitech)
  1833.         CONF_MOUSE1_TYPE="Logitech"
  1834.         CONF_MOUSE1_X_TYPE="logitech"
  1835.         #CONF_MOUSE1_DEV="serial"
  1836.         MOUSETYPE=logitech
  1837.         PROTO=logi
  1838.         DRIVER=psaux
  1839.         ;;
  1840.     Microsoft|microsoft)
  1841.         CONF_MOUSE1_TYPE="Microsoft"
  1842.         CONF_MOUSE1_X_TYPE="microsoft"
  1843.         MOUSETYPE=microsoft
  1844.         PROTO=ms
  1845.         DRIVER=psaux
  1846.         ;;
  1847.     USB|usb)
  1848.         CONF_MOUSE1_TYPE="USB"
  1849.         CONF_MOUSE1_X_TYPE="PS/2"
  1850.         MOUSETYPE=usb
  1851.         PROTO=ps2
  1852.         DRIVER=usb
  1853.         ;;
  1854.     busmouse)
  1855.         MOUSETYPE=busmouse
  1856.         PROTO=bm
  1857.         DRIVER=busmouse
  1858.         ;;
  1859.     mousesystems)
  1860.         MOUSETYPE=mousesystems
  1861.         PROTO=msc
  1862.         DRIVER="$CONF_MOUSE1_DEV"
  1863.         ;;
  1864.     esac
  1865.  
  1866.     # set /etc/system.cnf
  1867.     mkdir -p $DIR_TARGET/etc
  1868.     Set_Val CONF_MOUSE1_TYPE "$CONF_MOUSE1_TYPE"
  1869.     Set_Val CONF_MOUSE1_X_TYPE "$CONF_MOUSE1_X_TYPE"
  1870.     Set_Val CONF_MOUSE1_DEV "$CONF_MOUSE1_DEV"
  1871.     Set_Val CONF_MOUSE1_BUTTONS "$CONF_MOUSE1_BUTTONS"
  1872.  
  1873.     # create /dev/mouse
  1874.     mkdir -p $DIR_TARGET/dev
  1875.     ln -sf $CONF_MOUSE1_DEV $DIR_TARGET/dev/mouse
  1876.  
  1877.     # set /etc/sysconfig/mouse
  1878.     mkdir -p $DIR_TARGET/etc/sysconfig
  1879.     touch $DIR_TARGET/etc/sysconfig/mouse
  1880.     set_val -f $DIR_TARGET/etc/sysconfig/mouse MOUSETYPE "$MOUSETYPE"
  1881.     set_val -f $DIR_TARGET/etc/sysconfig/mouse PROTO "$PROTO"
  1882.     set_val -f $DIR_TARGET/etc/sysconfig/mouse DEVICE "$CONF_MOUSE1_DEV"
  1883.     if [ "$CONF_MOUSE1_BUTTONS" = "2" ]; then
  1884.         XEMU3=yes
  1885.     fi
  1886.     set_val -f $DIR_TARGET/etc/sysconfig/mouse XEMU3 "$XEMU3"
  1887.     set_val -f $DIR_TARGET/etc/sysconfig/mouse DRIVER "$DRIVER"
  1888. }
  1889.  
  1890.  
  1891. Fix_Videomode()
  1892. {
  1893.     # source what lizard dumped into /tmp/videomode
  1894.     if [ -f /tmp/videomode ]; then
  1895.         . /tmp/videomode
  1896.     else
  1897.         CONF_GRAPHIC_CARD1_VESAMODE=274
  1898.     fi
  1899.  
  1900.     # set /etc/system.cnf
  1901.     Set_Val CONF_GRAPHIC_CARD1_VESAMODE "$CONF_GRAPHIC_CARD1_VESAMODE"
  1902.  
  1903.     # dirty hack
  1904.     # FIXME for COL 2.4
  1905.     sed '/CONF_GRAPHIC_CARD1_VESAMODE/s/\"//g' $DIR_TARGET/etc/system.cnf > $DIR_TARGET/etc/system.cnf.tmp
  1906.     mv $DIR_TARGET/etc/system.cnf.tmp $DIR_TARGET/etc/system.cnf
  1907.  
  1908.     return 0
  1909. }
  1910.  
  1911.  
  1912. # The file $override_list contains a list of all override modules that
  1913. # loaded successfully. They still should be present (uncompressed) in the
  1914. # ramdisk, so we try to find them and copy them into the target system,
  1915. # overriding any existing ones.
  1916. #
  1917. Fix_override_modules()
  1918. {
  1919.     local i
  1920.     local module
  1921.     local override_module
  1922.     local override_list=/tmp/modules.override
  1923.  
  1924.     if [ -s $override_list ]; then
  1925.         for i in `cat $override_list` ; do
  1926.                        for override_module in /lib/modules/*/*/${i}.o \
  1927.                                 /lib/modules/*/*/*/${i}.o \
  1928.                                 /lib/modules/*/*/*/*/${i}.o \
  1929.                                 /lib/modules/*/*/*/*/*/${i}.o ; do
  1930.                 if [ -f $override_module ]; then
  1931.                     module="`echo $override_module | cut -c10-`"
  1932.                     mkdir -p $DIR_TARGET/`dirname $module`
  1933.                     cp -af $override_module $DIR_TARGET/$module
  1934.                     break
  1935.                 fi
  1936.             done
  1937.         done
  1938.     fi
  1939. }
  1940.  
  1941.  
  1942. Fix_XFree86()
  1943. {
  1944.     # source what lizard dumped into /tmp/xserver
  1945.     if [ -f /tmp/xserver ]; then
  1946.         . /tmp/xserver
  1947.     else
  1948.         CONF_X_SERVER1_TYPE="XF86_SVGA"
  1949.         CONF_X_SERVER1_RESOL=""
  1950.         CONF_X_KEYBOARD_MAP=""
  1951.     fi
  1952.  
  1953.     if [ -n "`sed -n '/^er=/p' /tmp/cmdline | fgrep vga`" ]; then
  1954.         CONF_X_SERVER1_TYPE="XF86_VGA16"
  1955.     fi
  1956.  
  1957.     # set /etc/system.cnf
  1958.     Set_Val CONF_X_SERVER1_TYPE "$CONF_X_SERVER1_TYPE"
  1959.     Set_Val CONF_X_SERVER1_RESOL "$CONF_X_SERVER1_RESOL"
  1960.     Set_Val CONF_X_KEYBOARD_MAP "$CONF_X_KEYBOARD_MAP"
  1961.  
  1962.     # create /usr/X11R6/bin/X symlink
  1963.     rm -f $DIR_TARGET/usr/X11R6/bin/X
  1964.     ln -s $CONF_X_SERVER1_TYPE $DIR_TARGET/usr/X11R6/bin/X
  1965.  
  1966.     # create generic XF86Config.vga16
  1967.     cp -p $DIR_LIVE_LIZARD/XF86Config $DIR_TARGET/etc/XF86Config.vga16
  1968.  
  1969.     return 0
  1970. }
  1971.  
  1972.  
  1973. Fix_group()
  1974. {
  1975.     sed 's/^users::100:.*$/users::100:/' $DIR_TARGET/etc/group > $DIR_TARGET/etc/group.tmp
  1976.     chmod 644 $DIR_TARGET/etc/group.tmp
  1977.     mv $DIR_TARGET/etc/group.tmp $DIR_TARGET/etc/group
  1978. }
  1979.  
  1980.  
  1981. Fix_root_home()
  1982. {
  1983.     local i
  1984.  
  1985.     rm -fr $DIR_TARGET/root
  1986.     cp -aR $DIR_TARGET/etc/skel $DIR_TARGET/root
  1987.     chown -R root.root $DIR_TARGET/root
  1988.     return 0
  1989. }
  1990.  
  1991.  
  1992. Fix_logins()
  1993. {
  1994.     Fix_group
  1995.     Fix_root_home
  1996. }
  1997.  
  1998.  
  1999. Get_kernel()
  2000. {
  2001.     local ret
  2002.     local f
  2003.     local what
  2004.     local flag
  2005.     local image
  2006.  
  2007.     case $1 in
  2008.     release|image)
  2009.         what=UTS_RELEASE
  2010.         flag=-r
  2011.         f=$DIR_TARGET/usr/src/linux/include/linux/version.h
  2012.         ;;
  2013.     version)
  2014.         what=UTS_VERSION
  2015.         flag=-v
  2016.         f=$DIR_TARGET/usr/src/linux/include/linux/compile.h
  2017.         ;;
  2018.     esac
  2019.  
  2020.     if [ -f $f ]; then
  2021.         ret="`fgrep $what $f | cut -d'"' -f 2`"
  2022.     else
  2023.         ret="`uname $flag`"
  2024.     fi
  2025.     case $1 in
  2026.     release|version)
  2027.         echo "$ret"
  2028.         return 0
  2029.         ;;
  2030.     image)
  2031.         image=/boot/vmlinuz-${ret}-modular
  2032.         if [ -f ${DIR_TARGET}${image} ]; then
  2033.             echo "$image"
  2034.             return 0
  2035.         elif [ -f ${DIR_TARGET}/boot/vmlinuz ]; then
  2036.             echo "/boot/vmlinuz"
  2037.             return 0
  2038.         elif [ -f ${DIR_TARGET}/vmlinuz ]; then
  2039.             echo "/vmlinuz"
  2040.             return 0
  2041.         fi
  2042.         ;;
  2043.     esac
  2044.     return 1
  2045. }
  2046.  
  2047.  
  2048. Is_SCSI_Root()
  2049. {
  2050.     Get_root dev | fgrep "/dev/sd" > /dev/null && return 0
  2051.     return 1
  2052. }
  2053.  
  2054.  
  2055. Set_modules_autoload()
  2056. {
  2057.     local uname_r="`Get_kernel release`"
  2058.     local uname_v="`Get_kernel version`"
  2059.     local confpath="/etc/modules/${uname_r}"
  2060.     local driver
  2061.     local mod_file
  2062.     local param_file
  2063.     local rootdev
  2064.  
  2065.     # modules that are loaded by other means (e.g. cardmgr)
  2066.     # should never be in those static modules load lists
  2067.     local otherload_modules_file=/tmp/modules.otherload
  2068.     # FIXME: static lists are evil
  2069.     local otherload_modules_list="3c574_cs 3c575_cb 3c589_cs aha152x_cs airo airo_cs apa1480_cb cb_enabler ds dummy_cs eepro100_cb epic_cb fdomain_cs fmvj18x_cs ftl_cs i82365 ibmtr_cs ide_cs iflash2+_mtd iflash2_mtd memory_cb memory_cs netwave_cs nmclan_cs parport_cs pcmcia_core pcnet_cs qlogic_cs ray_cs serial_cb serial_cs smc91c92_cs sram_mtd tcic tulip_cb wavelan_cs wvlan_cs xirc2ps_cs"
  2070.     touch $otherload_modules_file
  2071.     for i in $otherload_modules_list ; do
  2072.         echo "$i" >> $otherload_modules_file
  2073.     done
  2074.  
  2075.     # modules loaded by LISA were stored in this file
  2076.     local lisa_modules_file=/tmp/modules.initrd
  2077.     touch $lisa_modules_file
  2078.  
  2079.     # modules already handled will be stored in this file
  2080.     local handled_modules_file=$DIR_TARGET/tmp/modules.handled
  2081.     mkdir -p $DIR_TARGET/tmp
  2082.     chmod 1777 $DIR_TARGET/tmp
  2083.     rm -f $handled_modules_file
  2084.     touch $handled_modules_file
  2085.     local never_modules="sunrpc lockd fat msdos umsdos vfat parport soundcore soundlow 8390 scsi_mod sd_mod sd sr_mod st sg nfs isofs lp slhc slip ppp ipx"
  2086.     for driver in $never_modules; do
  2087.         echo $driver >> $handled_modules_file
  2088.     done
  2089.     # modules needed for the rootfs will be stored in this file
  2090.     # FIXME12uname: because of the rebuild uname -v causes problems
  2091.     local rootfs_modules_file="$DIR_TARGET$confpath/${uname_v}.rootfs"
  2092.     mkdir -p $DIR_TARGET$confpath
  2093.     rm -f "$rootfs_modules_file"
  2094.     touch "$rootfs_modules_file"
  2095.  
  2096.     # modules not needed for the rootfs will be stored in this file
  2097.     # FIXME12uname: because of the rebuild uname -v causes problems
  2098.     local non_rootfs_modules_file="$DIR_TARGET$confpath/${uname_v}.default"
  2099.     mkdir -p $DIR_TARGET/etc/modules/options
  2100.     mkdir -p $DIR_TARGET$confpath
  2101.     rm -f "$non_rootfs_modules_file"
  2102.     touch "$non_rootfs_modules_file"
  2103.  
  2104.     # The list of modules to be autoloaded consists of 3 parts:
  2105.     # 1. modules loaded by LISA (during autoprobing and on user's request)
  2106.     local lisa_modules="`cat $lisa_modules_file`"
  2107.     # 2. modules that are loaded now (to catch manually loaded modules)
  2108.     local loaded_modules="`cat /proc/modules | cut -d' ' -f 1`"
  2109.     # 3. modules that we want always to be loaded 
  2110.     #local default_modules="sunrpc lockd fat msdos umsdos vfat parport parport_pc parport_probe soundcore soundlow 8390 scsi_mod sd_mod sd sr_mod st sg nfs isofs lp slhc slip ppp ipx"
  2111.     # only 
  2112.     local default_modules="parport_pc parport_probe"
  2113.  
  2114.     # The modules may be autoloaded in 2 steps:
  2115.     # 1. modules required to load the root filesystem
  2116.     #    (this is only necessary if rootfs on a SCSI device)
  2117.     local need_initrd=
  2118.     # 2. other modules 
  2119.  
  2120.     # check if rootfs on non IDE controller
  2121.     rootdev="`sed -n '/ \/mnt\/root /p' /proc/mounts | cut -d' ' -f 1`"
  2122.     echo $rootdev | fgrep /dev/hd >/dev/null || need_initrd=true
  2123.  
  2124.     # store modules and their params in the appropriate autoload files
  2125.     for driver in $lisa_modules $loaded_modules $default_modules ; do
  2126.         if [ -n "`fgrep -x $driver "$otherload_modules_file"`" ]; then
  2127.             continue
  2128.         fi
  2129.         if [ -n "`fgrep -x $driver "$handled_modules_file"`" ]; then
  2130.             continue
  2131.         fi
  2132.         echo "$driver" >> "$handled_modules_file"
  2133.         mod_file="$non_rootfs_modules_file"
  2134.         param_file="$DIR_TARGET/etc/modules/options/$driver"
  2135.         if [ -n "$need_initrd" ]; then
  2136.             # FIXME: dumb check for scsi (should be done by sysinfo)
  2137.             if [ -f /lib/modules/${uname_r}/kernel/drivers/scsi/$driver.o ]; then
  2138.                 mod_file="$rootfs_modules_file"
  2139.             fi
  2140.             # FIXME: quick hack for public beta: aic7xxx has moved
  2141.             if [ -f /lib/modules/${uname_r}/kernel/drivers/scsi/aic7xxx/$driver.o ]; then
  2142.                 mod_file="$rootfs_modules_file"
  2143.             fi
  2144.             if [ -f /lib/modules/${uname_r}/kernel/drivers/block/$driver.o ]; then
  2145.                 mod_file="$rootfs_modules_file"
  2146.             fi
  2147.         fi
  2148.         echo "$driver" >> "$mod_file"
  2149.         if [ -s /etc/modules/options/$driver ]; then
  2150.             cp -a /etc/modules/options/$driver $param_file
  2151.         fi
  2152.     done
  2153.     [ -f "$rootfs_modules_file" ] && {
  2154.         mv "$rootfs_modules_file" "$rootfs_modules_file".tmp
  2155.         # 'scsi_mod' is the first thing to load in initrd...
  2156.         $need_initrd && echo "scsi_mod" > "$rootfs_modules_file"
  2157.         # then what's been found...
  2158.         cat "$rootfs_modules_file".tmp >> "$rootfs_modules_file"
  2159.         rm -f "$rootfs_modules_file".tmp
  2160.         # 'sd_mod' is the last(!) thing to be loaded in initrd...
  2161.         $need_initrd && echo "sd_mod" >> "$rootfs_modules_file"
  2162.         $need_initrd && echo "sd" >> "$rootfs_modules_file"
  2163.     }
  2164.  
  2165.     cp -a "$rootfs_modules_file" /etc/modules/rootfs
  2166.     cp -a "$rootfs_modules_file" $DIR_TARGET$confpath/rootfs
  2167.     cp -a "$non_rootfs_modules_file" $DIR_TARGET$confpath/default
  2168. }
  2169.  
  2170.  
  2171. Set_modules()
  2172. {
  2173.     # fix modules:
  2174.     # - create /etc/modules/`uname -r`/"`uname -v`.default"
  2175.     Set_modules_autoload
  2176.     return 0
  2177. }
  2178.  
  2179.  
  2180. Prepare_Initrd()
  2181. {
  2182.     # FIXME12uname: because of the rebuild uname -v causes problems
  2183.     local uname_r="`Get_kernel release`"
  2184.     local uname_v="`Get_kernel version`"
  2185.     local mod_file="/etc/modules/${uname_r}/${uname_v}.rootfs"
  2186.     local driver
  2187.     local moddir
  2188.     local module
  2189.     local ans
  2190.  
  2191.     # create minimal directories
  2192.     mkdir -p bin dev etc/rc.d etc/modules/${uname_r} \
  2193.         etc/modules/options lib/modules/${uname_r} sbin
  2194.  
  2195.     # create minimal devices
  2196.     mknod -m 644 dev/tty0 c 4 0
  2197.     mknod -m 644 dev/tty1 c 4 1
  2198.     ln -s tty0 dev/console
  2199.  
  2200.     # copy minimal libraries
  2201.     cp -a /lib/libc* lib
  2202.     cp -a /lib/ld.so* lib
  2203.     cp -a /etc/ld.so.conf etc
  2204.  
  2205.     # copy minimal binaries
  2206.     cp -a /bin/sh bin
  2207.     cp -a /sbin/insmod sbin
  2208.     cp -a /bin/uname bin
  2209.     cp -a /bin/cat bin
  2210.  
  2211.         for moddir in kernel/drivers/block \
  2212.                 kernel/drivers/cdrom \
  2213.                 kernel/drivers/net/tulip \
  2214.                 kernel/drivers/ide \
  2215.                 kernel/drivers/parport \
  2216.                 kernel/drivers/pnp \
  2217.                 kernel/drivers/sound \
  2218.                 kernel/drivers/scsi \
  2219.                 kernel/drivers/usb \
  2220.                 kernel/net/sunrpc \
  2221.                 kernel/fs \
  2222.                 pcmcia ; do
  2223.         mkdir -p ./lib/modules/${uname_r}/$moddir
  2224.     done
  2225.  
  2226.     # copy rootfs module list and corresponding modules and params files
  2227.     if [ -f "$DIR_TARGET/$mod_file" ]; then
  2228.         cp -a "$DIR_TARGET/$mod_file" ./"$mod_file"
  2229.         cp -a "$DIR_TARGET/$mod_file" ./etc/modules/${uname_r}/rootfs
  2230.         cp -a "$DIR_TARGET/$mod_file" $DIR_TARGET/etc/modules/rootfs
  2231.         # copy necessary modules
  2232.         for driver in `cat "$DIR_TARGET/$mod_file"` ; do
  2233.                         for moddir in kernel/drivers/block \
  2234.                                 kernel/drivers/cdrom \
  2235.                                 kernel/drivers/net \
  2236.                                 kernel/drivers/ide \
  2237.                                 kernel/drivers/parport \
  2238.                                 kernel/drivers/pnp \
  2239.                                 kernel/drivers/sound \
  2240.                                 kernel/drivers/scsi \
  2241.                                 kernel/drivers/usb \
  2242.                                 kernel/net/sunrpc \
  2243.                                 kernel/fs \
  2244.                                 pcmcia ; do
  2245.                 module=/lib/modules/${uname_r}/$moddir/${driver}.o
  2246.                 # we use the modules from the target system
  2247.                 if [ -f $DIR_TARGET/$module ]; then
  2248.                     mkdir -p ./lib/modules/${uname_r}/$moddir
  2249.                     cp -a $DIR_TARGET/$module ./$module
  2250.                 fi
  2251.             done
  2252.             if [ -s /etc/modules/options/$driver ]; then
  2253.                 cp -a /etc/modules/options/$driver etc/modules/options
  2254.             fi
  2255.         done
  2256.     fi
  2257.  
  2258.     # copy module autoload routine
  2259.     cp -a /etc/rc.d/rc.rootfs etc/rc.d
  2260.  
  2261.     # this is used to trigger a initrd umount and freeramdisk in rc.boot
  2262.     touch free_initrd
  2263.  
  2264.     # create a very simple linuxrc
  2265.     echo '#!/bin/sh' > linuxrc
  2266.     echo "/bin/sh /etc/rc.d/rc.rootfs" >> linuxrc
  2267.     echo "exit 0" >> linuxrc
  2268.     chmod 755 linuxrc
  2269. }
  2270.  
  2271.  
  2272. Create_Initrd()
  2273. {
  2274.     local f=$DIR_TARGET/tmp/loopfile
  2275.     local size=2880
  2276.     local mnt=$DIR_TARGET/mnt/tmp
  2277.     local img=$DIR_TARGET/boot/initrd.gz
  2278.     local dev=""
  2279.  
  2280.     mkdir -p $mnt
  2281.     Load_Default_Modules loop
  2282.     if insmod loop; then
  2283.         dev=/dev/loop0
  2284.         dd if=/dev/zero of=$f bs=1k count=$size 2> /dev/null
  2285.         [ -b $dev ] || mknod -m 666 $dev b 7 0
  2286.         losetup $dev $f
  2287.     else
  2288.         # fall back to more expensive ram-disk...
  2289.         dev=/dev/ram2
  2290.         [ -b $dev ] || mknod -m 666 $dev b 1 2
  2291.     fi
  2292.     mke2fs $dev $size 2> /dev/null
  2293.     mount -t ext2 $dev $mnt > /dev/null 2>&1
  2294.     ( cd $mnt ; Prepare_Initrd )
  2295.     umount $dev
  2296.     dd if=$dev bs=1k count=$size 2> /dev/null | gzip -9 > $img
  2297.  
  2298.     if [ $dev = /dev/loop0 ]; then
  2299.         losetup -d $dev
  2300.         rmmod loop
  2301.         rm -f $f
  2302.     else
  2303.         freeramdisk $dev
  2304.     fi
  2305. }
  2306.  
  2307.  
  2308. Is_DAC960_Root()
  2309. {
  2310.     Get_root dev | fgrep "/dev/rd/" > /dev/null && return 0
  2311.     Get_root dev | fgrep "/dev/ida/" > /dev/null && return 0
  2312.     Get_root dev | fgrep "/dev/cciss/" > /dev/null && return 0
  2313.     return 1
  2314. }
  2315.  
  2316.  
  2317. Set_initrd()
  2318. {
  2319.     local need_initrd=
  2320.  
  2321.     Is_SCSI_Root && need_initrd=true
  2322.     Is_DAC960_Root && need_initrd=true
  2323.     if [ -n "$need_initrd" ]; then
  2324.         # we need a initrd
  2325.         Create_Initrd
  2326.     else
  2327.         # we don't need a initrd
  2328.         rm -fr $DIR_TARGET/initrd/*
  2329.     fi
  2330.     return 0
  2331. }
  2332.  
  2333.  
  2334. Is_SPARC()
  2335. {
  2336.  
  2337.     if [ "`uname -m`" = "sparc" -o "`uname -m`" = "sparc64" ]; then
  2338.         return 0
  2339.     else
  2340.         return 1
  2341.     fi
  2342. }
  2343.  
  2344.  
  2345. Set_lilo()
  2346. {
  2347.     local f=$DIR_TARGET/etc/lilo.conf
  2348.     local dev="`Get_root dev`"
  2349.     local image="`Get_kernel image`"
  2350.     local append="append = \"quiet\""
  2351.     local initrd=
  2352.     local lilo_cmd=lilo
  2353.  
  2354.     if [ -f $FILE_LIZARD_RULES ]; then
  2355.         # simulate what newer lizards normally do
  2356.         mkdir -p $DIR_TARGET/etc
  2357.         if [ -n "`get_val CONF_INSTALL_LILO`" ]; then
  2358.             dev="`get_val CONF_INSTALL_LILO`"
  2359.         fi
  2360.         cat << EOF > $f
  2361. #
  2362. # /etc/lilo.conf - generated by Lizard
  2363. #
  2364.  
  2365. # target
  2366.  
  2367. boot = $dev
  2368. install = /boot/boot.b
  2369.  
  2370. # options
  2371.  
  2372. prompt
  2373. delay = 50
  2374. timeout = 50
  2375. message = /boot/message
  2376.  
  2377. default = linux
  2378.  
  2379. EOF
  2380.     fi
  2381.     if [ -f $f ]; then
  2382.         # lizard >= 990720 creates an /etc/lilo.conf template
  2383.         # linux-kernel-binary postin script finishes the work
  2384.         # so nothing to do directly from /linuxrc any more
  2385.         return 0
  2386.     fi
  2387.     Set_initrd
  2388.     if [ -f $DIR_TARGET/boot/initrd.gz ]; then
  2389.         append="append = \"quiet\""
  2390.         initrd="initrd = /boot/initrd.gz"
  2391.     fi
  2392.     # old lizard, so we have to do everything
  2393.     mkdir -p $DIR_TARGET/boot
  2394.     if [ ! -f $DIR_TARGET/boot/message ]; then
  2395.         cp -a /boot/message $DIR_TARGET/boot/message
  2396.     fi
  2397.     mkdir -p $DIR_TARGET/etc
  2398.     cat << EOF > $f
  2399. #
  2400. # general section
  2401. #
  2402. EOF
  2403.     if Is_SPARC ; then
  2404.             cat << EOF >> $f
  2405. partition = 1
  2406. EOF
  2407.     else
  2408.             cat << EOF >> $f
  2409. boot = $dev
  2410. install = /boot/boot.b
  2411. EOF
  2412.     fi
  2413.     cat << EOF >> $f
  2414. message = /boot/message
  2415. prompt
  2416.  
  2417. # wait 5 seconds (50 10ths) for user to select the entry to load
  2418. timeout = 50
  2419.  
  2420. #
  2421. # default entry
  2422. #
  2423.  
  2424. EOF
  2425.     cat << EOF >> $f
  2426. image = $image
  2427.         label = linux
  2428.         root = $dev
  2429.     vga = 274
  2430.         read-only
  2431.     $append
  2432.     $initrd
  2433.  
  2434. #
  2435. # additional entries
  2436. #
  2437.  
  2438. EOF
  2439.     chmod 600 $f
  2440.     if Is_SPARC; then
  2441.         mv $f $DIR_TARGET/etc/silo.conf
  2442.         lilo_cmd=silo
  2443.     fi
  2444.     ( cd $DIR_TARGET; chroot $DIR_TARGET sbin/$lilo_cmd && echo "LILO ok" ) > $DIR_TARGET/tmp/lilo.error 2>&1    
  2445.     return 0
  2446. }
  2447.  
  2448.  
  2449. Check_LILO()
  2450. {
  2451.     rm -f /tmp/mbr
  2452.     if [ $# -gt 0 ]; then
  2453.         dd if=$1 bs=1 skip=2 count=4 of=/tmp/mbr 2> /dev/null
  2454.     else
  2455.         dd if=/dev/hda bs=1 skip=2 count=4 of=/tmp/mbr 2> /dev/null
  2456.         if [ ! -s /tmp/mbr ]; then
  2457.             dd if=/dev/sda bs=1 skip=2 count=4 of=/tmp/mbr 2> /dev/null
  2458.         fi
  2459.     fi
  2460.  
  2461.     if [ ! -s /tmp/mbr ]; then
  2462.         rm -f /tmp/mbr
  2463.         return 1
  2464.     else
  2465.         fgrep LILO /tmp/mbr > /dev/null
  2466.         if [ $? -eq 0 ]; then
  2467.             ANSWER="LILO"
  2468.         else
  2469.             ANSWER="unknown"
  2470.         fi
  2471.     fi
  2472.     rm -f /tmp/mbr
  2473.     return 0
  2474. }
  2475.  
  2476.  
  2477. Do_Analyse_Boot_Setup()
  2478. {
  2479.     local mbr=
  2480.     local dummy=
  2481.     local bios_boot=
  2482.     local active_partitions=
  2483.     local os2_bootmgr=
  2484.     local lilo_in_mbr=
  2485.  
  2486.     # check if there is a LILO in the MBR
  2487.     mbr="`sysinfo --tag -C MBR --disk`"
  2488.     Check_LILO $mbr
  2489.     if [ $? -eq 0 -a "$ANSWER" = "LILO" ]; then
  2490.         lilo_in_mbr=true
  2491.     else
  2492.         lilo_in_mbr=false
  2493.     fi
  2494.     echo
  2495.  
  2496.     # first look for active partitions
  2497.     active_partitions="`sysinfo --tag -C active --partition`"
  2498.     if [ -z "$active_partitions" ]; then
  2499.         echo "No active partitions found!"
  2500.     else
  2501.         sysinfo --label -C active --partition
  2502.     fi
  2503.  
  2504.     if [ -n "$lilo_in_mbr" ]; then
  2505.         #echo "===> The BIOS will boot from the master boot record $mbr."
  2506.         return 0
  2507.     fi
  2508.     # the BIOS will boot from the first active partition
  2509.     bios_boot="`sysinfo --tag -C active --partition | sed -n '1p'`"
  2510.     if [ -z "$bios_boot" ]; then
  2511.         #echo "===> it seems you have no valid boot setup!"
  2512.         #echo "===> you have 2 choices to fix that:"
  2513.         #echo "A.) install a boot loader/manager in the master boot record"
  2514.         #echo "    of your first hard disk."
  2515.         #echo "B.) install a boot loader/manager in a primary partition on"
  2516.         #echo "    the first hard disk and activate this partition."
  2517.         #echo
  2518.         return 1
  2519.     fi
  2520.     #echo "===> The BIOS will boot the first active partition $bios_boot."
  2521.     Check_LILO $bios_boot
  2522.     if [ $? -eq 0 -a "$ANSWER" = "LILO" ]; then
  2523.         echo "===> $bios_boot seems to contain a LILO boot manager."
  2524.     else
  2525.         # check for DOSC
  2526.         if [ "$bios_boot" = "`sysinfo --tag -C DOSC --partition`" ]; then
  2527.             echo "===> $bios_boot seems to contain a DOS boot loader."
  2528.         # check for OS/2 Bootmanager
  2529.         elif [ "$bios_boot" = "`sysinfo --tag -C Bootmanager --partition | fgrep -x $bios_boot`" ]; then
  2530.             echo "===> $bios_boot seems to contain a OS/2 boot manager."
  2531.         # check for BSD Bootmanager
  2532.         elif [ "$bios_boot" = "`sysinfo --tag -C BSD --partition | fgrep -x $bios_boot`" ]; then
  2533.             echo "===> $bios_boot seems to contain a BSD boot manager."
  2534.         # check for Solaris Bootmanager
  2535.         elif [ "$bios_boot" = "`sysinfo --tag -C Solaris --partition | fgrep -x $bios_boot`" ]; then
  2536.             echo "===> $bios_boot seems to contain a Solaris boot manager."
  2537.         else
  2538.             echo "===> $bios_boot seems to contain no (or an unknown) boot manager."
  2539.         fi
  2540.     fi
  2541.     return 0
  2542. }
  2543.  
  2544.  
  2545. Do_Activate_Partition()
  2546. {
  2547.     local dummy=
  2548.     local hd_dev=
  2549.     local hd_part=
  2550.  
  2551.     hd_dev=`echo "$1" | cut -d'/' -f1-3`
  2552.     if [ "$hd_dev" = "/dev/rd" ]; then
  2553.         hd_dev=`echo "$1" | cut -c 1-12`
  2554.         hd_part=`echo "$1" | cut -c 14-`
  2555.     elif [ "$hd_dev" = "/dev/ida" ]; then
  2556.         hd_dev=`echo "$1" | cut -c 1-13`
  2557.         hd_part=`echo "$1" | cut -c 15-`
  2558.     elif [ "$hd_dev" = "/dev/cciss" ]; then
  2559.         hd_dev=`echo "$1" | cut -c 1-15`
  2560.         hd_part=`echo "$1" | cut -c 17-`
  2561.     else
  2562.         hd_part=`echo "$1" | cut -c 9-`
  2563.     fi
  2564.     dummy="$hd_dev $hd_part"
  2565.     activate $dummy 2> $FILE_TMP_ERR
  2566.     if [ $? -eq 0 ]; then
  2567.         Debug ":INFO_ACTIVATE_SUCCESS:"
  2568.     else
  2569.         Debug "$1: :ERR_ACTIVATE_PROBLEMS:"
  2570.         touch $FILE_TMP_ERR
  2571.         return 1
  2572.     fi
  2573.     return 0
  2574. }
  2575.  
  2576.  
  2577. Get_MBR_dev()
  2578. {
  2579.     sysinfo --tag -C MBR --disk
  2580. }
  2581.  
  2582.  
  2583. Replace_MBR()
  2584. {
  2585.     local src=/boot/bsd.mbr
  2586.     local tgt=$1
  2587.     local tmpf=/tmp/mbr.new
  2588.  
  2589.     if [ ! -f $src ]; then
  2590.         Debug "could not find $src to replace $tgt"
  2591.         return 1
  2592.     fi
  2593.  
  2594.     # make a working copy of our original
  2595.     cp $src $tmpf || { Debug "cp MBR->/tmp -- no space ?"; return 1; }
  2596.  
  2597.     # merge the partition table in case there is one
  2598.     dd if=$tgt of=$tmpf bs=1 count=64 skip=446 seek=446 2> /dev/null
  2599.  
  2600.     # and write it back onto the disk
  2601.     dd if=$tmpf of=$tgt count=1 2> /dev/null && {
  2602.         Debug "sucessfully replaced $tgt with $src"
  2603.         rm -f $tmpf
  2604.         return 0
  2605.     }
  2606.  
  2607.     rm -f $tmpf
  2608.     Debug "problems replacing $tgt"
  2609.     return 1
  2610. }
  2611.  
  2612.  
  2613. Do_Fix_MBR()
  2614. {
  2615.     local mbr_dev=
  2616.     local cbcode=/tmp/cmbr
  2617.  
  2618.     mbr_dev="`Get_MBR_dev`"
  2619.     if [ -z "$mbr_dev" ]; then
  2620.         Debug "Get_MBR_dev returned nothing"
  2621.         return 1
  2622.     fi
  2623.  
  2624.     # Measure the entropy of the boot code: meaningful code compresses
  2625.     # by far worse than identical byte patterns. -- td 1999-04-01
  2626.  
  2627.     dd if=$mbr_dev bs=446 count=1 2>/dev/null | gzip -9nf | \
  2628.     dd bs=70 skip=1 > $cbcode 2>/dev/null    # chop off first ~70 bytes
  2629.  
  2630.     if [ -s $cbcode ]; then
  2631.         # This means there's sufficient entropy in the boot code.
  2632.         # For now be happy with that 
  2633.         # (simplified approach -- see TODO below)
  2634.         rm -f $cbcode
  2635.         return 0
  2636.     fi
  2637.     rm -f $cbcode
  2638.     Debug "Compressed MBR code appears too small to work ==> replacing MBR"
  2639.     Replace_MBR $mbr_dev || return 1
  2640.     return 0
  2641.  
  2642.     # outline of complete algorithm
  2643.     # first of all examine MBR
  2644.     # if [ MBR code appears 2 B empty ]; then
  2645.     #    override it with our MBR (head 446, <orig parttab>, tail 2)
  2646.     #    return 0 (0 means fixed)
  2647.     # else
  2648.     #     if [ ! MBR is a LILO ]; then
  2649.     #        better leave it untouched
  2650.     #        return 2 (2 means maybe)
  2651.     #    TODO: "
  2652.     #     else
  2653.     #        if [ ! LILO is valid (how to test that ???)]; then
  2654.     #            replace with our MBR (head 446, tail 2)
  2655.     #            return 0 (0 means fixed)
  2656.     #        else
  2657.     #        fi
  2658.     #    fi
  2659.     #    "
  2660.     # fi
  2661. }
  2662.  
  2663.  
  2664. Set_MBR()
  2665. {
  2666.     Do_Fix_MBR || return 1
  2667.     return 0
  2668.     #Do_Analyse_Boot_Setup
  2669.     #Do_Activate_Partition
  2670. }
  2671.  
  2672.  
  2673. Fix_lisa()
  2674. {
  2675.     set_val -f $DIR_TARGET/etc/system.cnf DIR_TARGET "/"
  2676.     set_val -f $DIR_TARGET/etc/system.cnf MODE_QUERY "prompt"
  2677.     return 0
  2678. }
  2679.  
  2680.  
  2681. Fix_network()
  2682. {
  2683.     # source what lizard dumped into /tmp/network
  2684.     if [ -f /tmp/network ]; then
  2685.         . /tmp/network
  2686.     else
  2687.         CONF_eth0_STAT=""
  2688.         CONF_eth0_IP="192.168.1.2"
  2689.         CONF_eth0_MASK="255.255.255.0"
  2690.         CONF_eth0_DYNAMIC=""
  2691.         CONF_ROUTER1_IP="192.168.1.1"
  2692.         CONF_FQ_HOSTNAME="noname.nodomain.nowhere"
  2693.         CONF_DNS_SERVER1_IP=""
  2694.         CONF_DNS_SERVER2_IP=""
  2695.         CONF_DNS_SERVER3_IP=""
  2696.         CONF_NIS_DOMAIN=""
  2697.         CONF_NIS_SERVER1_IP=""
  2698.         CONF_NIS_SERVER2_IP=""
  2699.         CONF_NIS_SERVER3_IP=""
  2700.     fi
  2701.  
  2702.     # append ".nodomain.nowhere" to FQHN if it was actually a shortname
  2703.     if [ -z "`echo $CONF_FQ_HOSTNAME | fgrep '.'`" ]; then
  2704.         CONF_FQ_HOSTNAME="${CONF_FQ_HOSTNAME}.nodomain.nowhere"
  2705.     fi
  2706.     
  2707.     # generate other config info
  2708.     CONF_NODENAME="`echo $CONF_FQ_HOSTNAME | cut -d'.' -f 1`"
  2709.     CONF_eth0_NAME="$CONF_FQ_HOSTNAME"
  2710.     #CONF_eth0_MASK="`do_netcalc -m $CONF_eth0_IP`"
  2711.     CONF_eth0_NET="`do_netcalc -n $CONF_eth0_IP $CONF_eth0_MASK`"
  2712.     CONF_eth0_BCAST="`do_netcalc -b $CONF_eth0_IP $CONF_eth0_MASK`"
  2713.     LINE_DYNAMIC1="DYNAMIC=$CONF_eth0_DYNAMIC"
  2714.     CONF_DNS_DOMAIN="`echo $CONF_FQ_HOSTNAME | cut -d'.' -f 2-`"
  2715.     LINE_DOMAIN="domain $CONF_DNS_DOMAIN"
  2716.     CONF_DNS_SEARCH="`echo $CONF_FQ_HOSTNAME | cut -d'.' -f 2-`"
  2717.     LINE_SEARCH="search $CONF_DNS_SEARCH"
  2718.     LINE_DNS_SERVER1=""
  2719.     LINE_DNS_SERVER2=""
  2720.     LINE_DNS_SERVER3=""
  2721.     if [ -n "$CONF_DNS_SERVER1_IP" -a "$CONF_DNS_SERVER1_IP" != "0.0.0.0" ]; then
  2722.         LINE_DNS_SERVER1="nameserver $CONF_DNS_SERVER1_IP"
  2723.     fi
  2724.     if [ -n "$CONF_DNS_SERVER2_IP" -a "$CONF_DNS_SERVER2_IP" != "0.0.0.0" ]; then
  2725.         LINE_DNS_SERVER2="nameserver $CONF_DNS_SERVER2_IP"
  2726.     fi
  2727.     if [ -n "$CONF_DNS_SERVER3_IP" -a "$CONF_DNS_SERVER3_IP" != "0.0.0.0" ]; then
  2728.         LINE_DNS_SERVER3="nameserver $CONF_DNS_SERVER3_IP"
  2729.     fi
  2730.     NETWORKING="yes"
  2731.     LINE_NETWORKING="NETWORKING=yes"
  2732.     if [ -n "`sed -e '1,3d' /proc/net/dev`" -a -n "$CONF_eth0_IP" -a "$CONF_eth0_IP" != "0.0.0.0" -a "$CONF_eth0_STAT" = "up" ]; then
  2733.         CONF_eth0_DEV="eth0"
  2734.         LINE_LOCALHOST="127.0.0.1 localhost"
  2735.         LINE_ETH0="$CONF_eth0_IP $CONF_FQ_HOSTNAME $CONF_NODENAME"
  2736.         LINE_ETH1=""
  2737.         if [ -z "$CONF_ROUTER1_IP" -o "$CONF_ROUTER1_IP" = "0.0.0.0" ]; then
  2738.             LINE_GATEWAY1="GATEWAY=none"
  2739.         else
  2740.             LINE_GATEWAY1="GATEWAY=$CONF_ROUTER1_IP"
  2741.         fi
  2742.         LINE_ONBOOT1="ONBOOT=yes"
  2743.     else
  2744.         CONF_eth0_DEV=""
  2745.         LINE_LOCALHOST="127.0.0.1 $CONF_FQ_HOSTNAME $CONF_NODENAME localhost"
  2746.         LINE_ETH0=""
  2747.         LINE_ETH1=""
  2748.         LINE_GATEWAY1="GATEWAY=none"
  2749.         LINE_ONBOOT1="ONBOOT=no"
  2750.     fi
  2751.     LINE_GATEWAY2="GATEWAY=none"
  2752.     LINE_ONBOOT2="ONBOOT=no"
  2753.     LINE_DYNAMIC2="DYNAMIC="
  2754.  
  2755.     LINE_NIS_DOMAIN=""
  2756.     LINE_NIS_SERVER1=""
  2757.     LINE_NIS_SERVER2=""
  2758.     LINE_NIS_SERVER3=""
  2759.  
  2760.     if [ -n "$CONF_NIS_DOMAIN" ]; then
  2761.         LINE_NIS_DOMAIN="domain $CONF_NIS_DOMAIN"
  2762.         # do not set domainname as it makes glibc-2.2 unhappy on boot
  2763.         # domainname $CONF_NIS_DOMAIN
  2764.     fi
  2765.     if [ -n "$CONF_NIS_SERVER1_IP" ]; then
  2766.         LINE_NIS_SERVER1="$LINE_NIS_DOMAIN server $CONF_NIS_SERVER1_IP"
  2767.     else
  2768.         LINE_NIS_SERVER2="$LINE_NIS_DOMAIN broadcast"
  2769.     fi
  2770.     if [ -n "$CONF_NIS_SERVER2_IP" ]; then
  2771.         LINE_NIS_SERVER2="ypserver $CONF_NIS_SERVER2_IP"
  2772.     fi
  2773.     if [ -n "$CONF_NIS_SERVER3_IP" ]; then
  2774.         LINE_NIS_SERVER3="ypserver $CONF_NIS_SERVER3_IP"
  2775.     fi
  2776.  
  2777.     # set /etc/system.cnf
  2778.     mkdir -p $DIR_TARGET/etc
  2779.     Set_Val CONF_FQ_HOSTNAME "$CONF_FQ_HOSTNAME"
  2780.     Set_Val CONF_NODENAME "$CONF_NODENAME"
  2781.     Set_Val CONF_eth0_STAT "$CONF_eth0_STAT"
  2782.     Set_Val CONF_eth0_DEV "$CONF_eth0_DEV"
  2783.     Set_Val CONF_eth0_NAME "$CONF_eth0_NAME"
  2784.     Set_Val CONF_eth0_IP "$CONF_eth0_IP"
  2785.     Set_Val CONF_eth0_MASK "$CONF_eth0_MASK"
  2786.     Set_Val CONF_eth0_NET "$CONF_eth0_NET"
  2787.     Set_Val CONF_eth0_BCAST "$CONF_eth0_BCAST"
  2788.     Set_Val CONF_eth0_DYNAMIC "$CONF_eth0_DYNAMIC"
  2789.     Set_Val CONF_eth1_STAT "$CONF_eth1_STAT"
  2790.     Set_Val CONF_eth1_DEV "$CONF_eth1_DEV"
  2791.     Set_Val CONF_eth1_NAME "$CONF_eth1_NAME"
  2792.     Set_Val CONF_eth1_IP "$CONF_eth1_IP"
  2793.     Set_Val CONF_eth1_MASK "$CONF_eth1_MASK"
  2794.     Set_Val CONF_eth1_NET "$CONF_eth1_NET"
  2795.     Set_Val CONF_eth1_BCAST "$CONF_eth1_BCAST"
  2796.     Set_Val CONF_eth1_DYNAMIC "$CONF_eth1_DYNAMIC"
  2797.     Set_Val CONF_ROUTER1_IP "$CONF_ROUTER1_IP"
  2798.     Set_Val CONF_DNS_DOMAIN "$CONF_DNS_DOMAIN"
  2799.     Set_Val CONF_DNS_SEARCH "$CONF_DNS_SEARCH"
  2800.     Set_Val CONF_DNS_SERVER1_IP "$CONF_DNS_SERVER1_IP"
  2801.     Set_Val CONF_DNS_SERVER2_IP "$CONF_DNS_SERVER2_IP"
  2802.     Set_Val CONF_DNS_SERVER3_IP "$CONF_DNS_SERVER3_IP"
  2803.     Set_Val CONF_NIS_DOMAIN "$CONF_NIS_DOMAIN"
  2804.     Set_Val CONF_NIS_SERVER1_IP "$CONF_NIS_SERVER1_IP"
  2805.     Set_Val CONF_NIS_SERVER2_IP "$CONF_NIS_SERVER2_IP"
  2806.     Set_Val CONF_NIS_SERVER3_IP "$CONF_NIS_SERVER3_IP"
  2807.  
  2808.     # create /etc/HOSTNAME
  2809.     cat << EOF > $DIR_TARGET/etc/HOSTNAME
  2810. $CONF_FQ_HOSTNAME
  2811. EOF
  2812.     chmod 644 $DIR_TARGET/etc/HOSTNAME
  2813.  
  2814.     # create /etc/hosts
  2815.     cat << EOF > $DIR_TARGET/etc/hosts
  2816. # /etc/hosts -  hostname_to_address mappings for the resolver library
  2817. #
  2818. # The format is:
  2819. #
  2820. # ipaddr fully_qualified_hostname list_of_nicknames
  2821. #
  2822. # We strongly recommend to use a fully qualified hostname for your machine
  2823. # if it is connected to any type of network. You can add short nicknames as
  2824. # you like, but the official canonical name is the name that follows the
  2825. # IP address and should always be a fully qualified hostname.
  2826. #
  2827. # If you don't have any network interfaces, you should put your hostname
  2828. # in the line of your loopback device, which has the address 127.0.0.1.
  2829. #
  2830. # LISA or COAS will automatically put the hostname in the right line for you.
  2831. #
  2832. #
  2833. # !!! Automatically generated by lizard. Do not edit !!!
  2834. #
  2835. # The loopback device. It should always be available.
  2836. #
  2837. $LINE_LOCALHOST
  2838. #
  2839. # Your first IP interface (if you are connected to any kind of network)
  2840. #
  2841. $LINE_ETH0
  2842.  
  2843. #
  2844. # Your second IP interface (normally for routers only)
  2845. #
  2846. $LINE_ETH1
  2847.  
  2848. #
  2849. # If you have a nameserver we recommend to use it instead of putting many
  2850. # hosts in this file. If you don't have a nameserver though, you can add
  2851. # hostnames and their IP addresses below this line.
  2852. #
  2853. #===========================================================================
  2854. EOF
  2855.     chmod 644 $DIR_TARGET/etc/hosts
  2856.  
  2857.     # create /etc/sysconfig/network
  2858.     mkdir -p $DIR_TARGET/etc/sysconfig
  2859.     cat << EOF > $DIR_TARGET/etc/sysconfig/network
  2860. $LINE_NETWORKING
  2861. HOSTNAME=$CONF_FQ_HOSTNAME
  2862. IF_LIST='lo eth tr sl ppp'
  2863. EOF
  2864.     chmod 644 $DIR_TARGET/etc/sysconfig/network
  2865.  
  2866.     # create /etc/sysconfig/network-scripts/ifcfg-lo
  2867.     mkdir -p $DIR_TARGET/etc/sysconfig/network-scripts
  2868.     # FIXME: check whether anything is necessary
  2869.  
  2870.     # create /etc/sysconfig/network-scripts/ifcfg-eth0
  2871.     mkdir -p $DIR_TARGET/etc/sysconfig/network-scripts
  2872.     cat << EOF > $DIR_TARGET/etc/sysconfig/network-scripts/ifcfg-eth0
  2873. #!/bin/sh
  2874. #>>>Device type: ethernet
  2875. #>>>Variable declarations:
  2876. DEVICE=$CONF_eth0_DEV
  2877. IPADDR=$CONF_eth0_IP
  2878. NETMASK=$CONF_eth0_MASK
  2879. NETWORK=$CONF_eth0_NET
  2880. BROADCAST=$CONF_eth0_BCAST
  2881. $LINE_GATEWAY1
  2882. $LINE_ONBOOT1
  2883. $LINE_DYNAMIC1
  2884. #>>>End variable declarations
  2885. EOF
  2886.     chmod 755 $DIR_TARGET/etc/sysconfig/network-scripts/ifcfg-eth0
  2887.  
  2888.     # create /etc/resolv.conf
  2889.     cat << EOF > $DIR_TARGET/etc/resolv.conf
  2890. # /etc/resolv.conf - DNS setup file
  2891. #
  2892. # possible entries are:
  2893. #
  2894. #       domain <domain>                 Local domain name. If not present, the
  2895. #                                       gethostbyname syscall is used to
  2896. #                                       determine the local domain name.
  2897. #
  2898. #       search <list_of_domains>        Search list for hostname lookup.
  2899. #                                       The search list is normally determined
  2900. #                                       from the local domain name but it
  2901. #                                       can be set to a list of domains.
  2902. #
  2903. #       nameserver <ip_addr>            Define which server to contact
  2904. #                                       for DNS lookups. If there are
  2905. #                                       multiple nameserver lines (Max=3),
  2906. #                                       they are queried in the listed order.
  2907. #
  2908. # !!! Automatically generated by lizard. Do not edit !!!
  2909. #
  2910. $LINE_DOMAIN
  2911. $LINE_SEARCH
  2912. $LINE_DNS_SERVER1
  2913. $LINE_DNS_SERVER2
  2914. $LINE_DNS_SERVER3
  2915. EOF
  2916.     chmod 644 $DIR_TARGET/etc/resolv.conf
  2917.  
  2918.     # create /etc/nis.conf
  2919.     cat << EOF > $DIR_TARGET/etc/nis.conf
  2920. # /etc/nis.conf - NIS setup file
  2921. #
  2922. # possible entries are:
  2923. #
  2924. #    domain <domain> broadcast    This is the default NIS domain;
  2925. #                    Broadcasts are used to find an
  2926. #                    eligible server (insecure).
  2927. #        alternatively
  2928. #
  2929. #    domain <domain> server <ip>    Additionally specify which host
  2930. #                    to contact for NIS service.
  2931. #
  2932. #    ypserver <ip>            Fall-Back servers for NIS can
  2933. #                    be added this way for the case
  2934. #                    that the primary server is down.
  2935. #
  2936. # !!! Automatically generated by lizard. Edit at your own risk !!!
  2937. #
  2938. $LINE_NIS_SERVER1
  2939. $LINE_NIS_SERVER2
  2940. $LINE_NIS_SERVER3
  2941. EOF
  2942.     chmod 644 $DIR_TARGET/etc/nis.conf
  2943.  
  2944.     # prepare passwd and group for NIS
  2945.     sed '/^\+/d' $DIR_TARGET/etc/passwd > $DIR_TARGET/etc/passwd.tmp
  2946.     sed '/^\+/d' $DIR_TARGET/etc/group > $DIR_TARGET/etc/group.tmp
  2947.     if [ -n "$CONF_NIS_DOMAIN" ]; then
  2948.         # add NIS lines to passwd and group if NIS domain set
  2949.         echo "+::::::"     >> $DIR_TARGET/etc/passwd.tmp
  2950.         echo "+:::"     >> $DIR_TARGET/etc/group.tmp
  2951.     fi
  2952.     chmod 644 $DIR_TARGET/etc/passwd.tmp
  2953.     chmod 644 $DIR_TARGET/etc/group.tmp
  2954.     mv $DIR_TARGET/etc/passwd.tmp $DIR_TARGET/etc/passwd
  2955.     mv $DIR_TARGET/etc/group.tmp $DIR_TARGET/etc/group
  2956.  
  2957.     # force nis-client to be started if NIS domain is set
  2958.     if [ -n "$CONF_NIS_DOMAIN" ]; then
  2959.         if [ -f $DIR_TARGET/etc/sysconfig/daemons/nis-client ]; then
  2960.             set_val -f $DIR_TARGET/etc/sysconfig/daemons/nis-client ONBOOT yes
  2961.         fi
  2962.     fi
  2963.  
  2964.     return 0
  2965. }
  2966.  
  2967.  
  2968. Prepare_save_initrd()
  2969. {
  2970.     # trigger a copy of the initrd we used for install under /var/tmp/initrd
  2971.     touch /save_initrd
  2972. }
  2973.  
  2974.  
  2975. Prepare_free_initrd()
  2976. {
  2977.     # trigger a initrd umount and freeramdisk in rc.boot
  2978.     touch /free_initrd
  2979. }
  2980.  
  2981.  
  2982. Fix_language()
  2983. {
  2984.     # source what lizard dumped into /tmp/language
  2985.     if [ -f /tmp/language ]; then
  2986.         . /tmp/language
  2987.     else
  2988.         CONF_LANGUAGE="english"
  2989.         CONF_PRINTER1_PAPER="letter"
  2990.     fi
  2991.     case $CONF_LANGUAGE in
  2992.     english|us)
  2993.         CONF_LST_LANG="us"
  2994.         CONF_PRINTER1_PAPER="letter"
  2995.         ;;
  2996.     german|de)
  2997.         CONF_LST_LANG="de"
  2998.         CONF_PRINTER1_PAPER="a4"
  2999.         ;;
  3000.     french|fr)
  3001.         CONF_LST_LANG="fr"
  3002.         CONF_PRINTER1_PAPER="a4"
  3003.         ;;
  3004.     italian|it)
  3005.         CONF_LST_LANG="it"
  3006.         CONF_PRINTER1_PAPER="a4"
  3007.         ;;
  3008.     esac
  3009.  
  3010.     # set /etc/system.cnf
  3011.     Set_Val CONF_LST_LANG "$CONF_LST_LANG"
  3012.     Set_Val CONF_PRINTER1_PAPER "$CONF_PRINTER1_PAPER"
  3013. }
  3014.  
  3015.  
  3016. Fix_PCMCIA()
  3017. {
  3018.     local pcic=""
  3019.  
  3020.     if [ -s /tmp/pcmcia.chip ]; then
  3021.         pcic="`cat /tmp/pcmcia.chip`"
  3022.         set_val -f $DIR_TARGET/etc/sysconfig/pcmcia PCMCIA yes
  3023.         set_val -f $DIR_TARGET/etc/sysconfig/pcmcia PCIC $pcic
  3024.     fi
  3025. }
  3026.  
  3027.  
  3028. Fix_Compaq_Devices_Copy()
  3029. {
  3030.     if [ -d /dev/ida -a ! -d $DIR_TARGET/dev/ida ]; then
  3031.         cp -aR /dev/ida $DIR_TARGET/dev/ida
  3032.     fi
  3033.     if [ -d /dev/cciss -a ! -d $DIR_TARGET/dev/cciss ]; then
  3034.         cp -aR /dev/cciss $DIR_TARGET/dev/cciss
  3035.     fi
  3036. }
  3037.  
  3038. Fix_Disk_Devices_Copy()
  3039. {
  3040.     # copies already used ones, but we have 'ash', which lacks good globbing
  3041.     cp -aR /dev/hd* /dev/sd* $DIR_TARGET/dev/
  3042. }
  3043.  
  3044. Fix_modules()
  3045. {
  3046.     local uname_r="`Get_kernel release`"
  3047.     local uname_v="`Get_kernel version`"
  3048.  
  3049.  
  3050.     if [ -f /etc/modules.conf ]; then
  3051.         cp -a /etc/modules.conf $DIR_TARGET/etc/modules.conf
  3052.     fi
  3053.     if [ -f /etc/modules/rootfs ]; then
  3054.         cp -a /etc/modules/rootfs $DIR_TARGET/etc/modules/rootfs
  3055.     fi
  3056.     if [ -f /etc/modules/default ]; then
  3057.         cp -a /etc/modules/default $DIR_TARGET/etc/modules/default
  3058.     fi
  3059.     # remove all old scheme modules load files
  3060.     rm -fr $DIR_TARGET/etc/modules/${uname_r}
  3061. }
  3062.  
  3063.  
  3064. Fix_grub_postin()
  3065. {
  3066.     mount -t proc /proc $DIR_TARGET/proc
  3067.     ( cd $DIR_TARGET; chroot $DIR_TARGET var/adm/LST/PostIn/*grub* && echo "grub postin ok" ) > $DIR_TARGET/tmp/grub.postin.log 2>&1    
  3068.     umount $DIR_TARGET/proc
  3069.     return 0
  3070. }
  3071.  
  3072.  
  3073. Fix_lizard_log_copy()
  3074. {
  3075.     if [ -f /tmp/lizard.log ]; then
  3076.         cp -a /tmp/lizard.log $DIR_TARGET/tmp/lizard.log
  3077.     fi
  3078.     if [ -f /var/log/update ]; then
  3079.         cp -a /var/log/update $DIR_TARGET/var/log/update
  3080.     fi
  3081. }
  3082.  
  3083.  
  3084. Fix_linux_kernel_binary_postin()
  3085. {
  3086.     local f=$DIR_TARGET/etc/lilo.conf
  3087.     local initrd=
  3088.     local recall_lilo=false
  3089.  
  3090.     # The linux-kernel-binary postin expands the template and
  3091.     # creates dynamically an initrd if needed
  3092.     mount -t proc /proc $DIR_TARGET/proc
  3093.     ( cd $DIR_TARGET; chroot $DIR_TARGET var/adm/LST/PostIn/*linux-kernel-binary* && echo "linux-kernel-binary postin ok" ) > $DIR_TARGET/tmp/linux-kernel-binary.postin.log 2>&1    
  3094.     umount $DIR_TARGET/proc
  3095.  
  3096.     # If root is on /dev/rd, /dev/ida, or /dev/cciss we have to add an
  3097.     # initrd line
  3098.     Is_DAC960_Root
  3099.     if [ $? -eq 0 ]; then
  3100.         echo "found root on DAC960, cpqarray, or cciss. Need to inject initrd line." >> $DIR_TARGET/tmp/lilo.fix.log
  3101.         initrd="/boot/initrd-`uname -r`.gz"
  3102.         if [ ! -f "${DIR_TARGET}${initrd}" ]; then
  3103.             echo "No initrd found. No way to fix it." >> $DIR_TARGET/tmp/lilo.fix.log
  3104.         elif [ -z "`sed -n '/[     ]*initrd[     ]*=/p' $f`"; then
  3105.             echo "initrd found. Injecting initrd line." >> $DIR_TARGET/tmp/lilo.fix.log
  3106.             recall_lilo=true
  3107.             # cut everything up to the linux entry
  3108.             sed -n '1,/label[     ]*=[     ]*linux/p' $f > ${f}.tmp
  3109.             cat << EOF >> ${f}.tmp
  3110.     initrd = $initrd
  3111. EOF
  3112.             sed -n '/label[     ]*=[     ]*linux/,$p' $f | sed '/label[     ]*=[     ]*linux/d' >> ${f}.tmp
  3113.             mv ${f}.tmp $f
  3114.             chmod 600 $f
  3115.         fi
  3116.     fi
  3117.  
  3118.     # If the root partition resides on a SCSI or RAID disk we enable linear
  3119.     Is_SCSI_Root || Is_DAC960_Root
  3120.     if [ $? -eq 0 ]; then
  3121.         echo "injecting linear option" >> $DIR_TARGET/tmp/lilo.fix.log
  3122.         recall_lilo=true
  3123.         # cut everything up to the install entry
  3124.         sed -n '1,/^install[     ]*=/p' $f > ${f}.tmp
  3125.         cat << EOF >> ${f}.tmp
  3126. linear
  3127. EOF
  3128.         sed -n '/^install[     ]*=/,$p' $f | sed '/^install[     ]*=/d' >> ${f}.tmp
  3129.         mv ${f}.tmp $f
  3130.         chmod 600 $f
  3131.     fi
  3132.  
  3133.     if [ "$recall_lilo" = "true" ]; then
  3134.         echo "recall_lilo=true. Recalling lilo." >> $DIR_TARGET/tmp/lilo.fix.log
  3135.         mount -t proc /proc $DIR_TARGET/proc
  3136.         ( cd $DIR_TARGET; chroot $DIR_TARGET sbin/lilo ) > $DIR_TARGET/tmp/lilo.again.log 2>&1
  3137.         umount $DIR_TARGET/proc
  3138.     else
  3139.         echo "recall_lilo=false. Do nothing." >> $DIR_TARGET/tmp/lilo.again.log
  3140.     fi
  3141.     return 0
  3142. }
  3143.  
  3144.  
  3145. Do_fix_ePanic()
  3146. {
  3147.     local what=$1
  3148.  
  3149.     if [ "$what" = "XFree_usr_adm" ]; then
  3150.         mkdir -p $DIR_TARGET/usr/adm
  3151.     elif [ "$what" = "ide-cd" ]; then
  3152.         insmod /lib/modules/`uname -r`/kernel/drivers/cdrom/cdrom.o
  3153.         insmod /lib/modules/`uname -r`/kernel/drivers/ide/ide-cd.o
  3154.     elif [ "$what" = "no-ide-cd" ]; then
  3155.         rmmod ide-cd
  3156.     elif [ "$what" = "bootpc" ]; then
  3157.         if [ -f /floppy/bootpc.out.fake ]; then
  3158.             cp -a /floppy/bootpc.out.fake /tmp/bootpc.out
  3159.             return 0
  3160.         elif [ -f /etc/bootpc.out.fake ]; then
  3161.             cp -a /etc/bootpc.out.fake /tmp/bootpc.out
  3162.             return 0
  3163.         else
  3164.             return 1
  3165.         fi
  3166.     elif [ "$what" = "af_packet" ]; then
  3167.         insmod /lib/modules/`uname -r`/kernel/drivers/misc/af_packet.o
  3168.     elif [ "$what" = "lsmod" ]; then
  3169.         rm -f /sbin/lsmod
  3170.         ln -s insmod /sbin/lsmod
  3171.     fi
  3172. }
  3173.  
  3174.  
  3175. Fix_grub_menu_lst()
  3176. {
  3177.     local f=$DIR_TARGET/boot/grub/menu.lst
  3178.  
  3179.     # ServerWorks PCI host bridges currently need noapic to work
  3180.     if [ -n "`fgrep 'Host bridge:' /proc/pci | fgrep ServerWorks`" ]; then
  3181.         sed 's/ quiet/ noapic quiet/' $f > ${f}.tmp
  3182.         chmod 644 ${f}.tmp
  3183.         mv ${f}.tmp $f
  3184.     fi
  3185.  
  3186.     # RAID devices root string is currently broken
  3187.     cp -a $DIR_LIVE_LIZARD/share/apps/lizard/fixes/fixroot.pl $DIR_TARGET/tmp/fixroot.pl
  3188.  
  3189.     mount -t proc /proc $DIR_TARGET/proc
  3190.     ( cd $DIR_TARGET; chroot $DIR_TARGET usr/bin/perl /tmp/fixroot.pl && echo "grub fix ok" ) > $DIR_TARGET/tmp/grub.fix.log 2>&1    
  3191.     umount $DIR_TARGET/proc
  3192.     return 0
  3193. }
  3194.  
  3195.  
  3196. Do_fix()
  3197. {
  3198.     local fixlist
  3199.     local fix
  3200.     local default_fixlist='1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19'
  3201.     local default_nextgen_fixlist='13 19'    # nearly empty
  3202.  
  3203.     # we now support a parameter fix=NUM(,NUM(,NUM(...)))
  3204.     # that allows us to dynamically turn on/off fixes
  3205.     fixlist="`sed -n '/^fix=/p' /tmp/cmdline | cut -d'=' -f 2 | sed 's/,/ /g'`"
  3206.     if [ -z "$fixlist" ]; then
  3207.         fixlist="$default_fixlist"
  3208.         # Only allow the short fixlist if we are neither in LUI
  3209.         # nor in LISA (text based) install mode
  3210.         if [ -z "`sed -n '/^lizard=/s/^lizard=//p' /tmp/cmdline`" -a -z "`sed -n '/^er=/p' /tmp/cmdline | fgrep text`" ]; then
  3211.             if [ -d $DIR_LIVE_LIZARD/share/apps/lizard/fixes ]; then
  3212.                 Debug "using new fix list"
  3213.                 fixlist="$default_nextgen_fixlist"
  3214.             fi
  3215.         fi
  3216.     fi
  3217.  
  3218.     for fix in $fixlist ; do
  3219.         case $fix in
  3220.         1)
  3221.             Debug "Running fix 1: Fix_etc_fstab"
  3222.             Fix_etc_fstab
  3223.             ;;
  3224.         2)
  3225.             Debug "Running fix 2: Fix_timezone"
  3226.             Fix_timezone
  3227.             ;;
  3228.         3)
  3229.             Debug "Running fix 3: Fix_mouse"
  3230.             Fix_mouse
  3231.             ;;
  3232.         4)
  3233.             Debug "Running fix 4: Fix_XFree86"
  3234.             Fix_XFree86
  3235.             ;;
  3236.         5)
  3237.             Debug "Running fix 5: Fix_network"
  3238.             Fix_network
  3239.             ;;
  3240.         6)
  3241.             Debug "Running fix 6: Fix_logins"
  3242.             Fix_logins
  3243.             ;;
  3244.         7)
  3245.             Debug "Running fix 7: Fix_lisa"
  3246.             Fix_lisa
  3247.             ;;
  3248.         8)
  3249.             Debug "Running fix 8: Fix_keyboard"
  3250.             Fix_keyboard
  3251.             ;;
  3252.         9)
  3253.             Debug "Running fix 9: Fix_language"
  3254.             Fix_language
  3255.             ;;
  3256.         10)
  3257.             Debug "Running fix 10: Fix_PCMCIA"
  3258.             Fix_PCMCIA
  3259.             ;;
  3260.         11)
  3261.             Debug "Running fix 11: Fix_Compaq_Devices_Copy"
  3262.             Fix_Compaq_Devices_Copy
  3263.             ;;
  3264.         12)
  3265.             Debug "Running fix 12: Fix_Disk_Devices_Copy"
  3266.             Fix_Disk_Devices_Copy
  3267.             ;;
  3268.         13)
  3269.             Debug "Running fix 13: Fix_modules"
  3270.             Fix_modules
  3271.             ;;
  3272.         14)
  3273.             Debug "Running fix 14: Fix_Videomode"
  3274.             Fix_Videomode
  3275.             ;;
  3276.         15)
  3277.             Debug "Running fix 15: Fix_override_modules"
  3278.             Fix_override_modules
  3279.             ;;
  3280.         16)
  3281.             Debug "Running fix 16: Fix_linux_kernel_binary_postin"
  3282.             Fix_linux_kernel_binary_postin
  3283.             ;;
  3284.         17)
  3285.             Debug "Running fix 17: Fix_grub_postin"
  3286.             Fix_grub_postin
  3287.             ;;
  3288.         18)
  3289.             Debug "Running fix 18: Fix_lizard_log_copy"
  3290.             Fix_lizard_log_copy
  3291.             ;;
  3292.         19)
  3293.             Debug "Running fix 19: Fix_grub_menu_lst"
  3294.             Fix_grub_menu_lst
  3295.             ;;
  3296.         esac
  3297. # Breakpoint "After fix $fix"
  3298.     done
  3299. }
  3300.  
  3301.  
  3302. Copy_hwinfo()
  3303. {
  3304.     if [ -x /bin/hwinfo ]; then
  3305.         cp -a /bin/hwinfo $DIR_TARGET/bin/hwinfo
  3306.     fi
  3307. }
  3308.  
  3309.  
  3310. Copy_mklizard()
  3311. {
  3312.     if [ -x /bin/mklizard ]; then
  3313.         cp -a /bin/mklizard $DIR_TARGET/bin/mklizard
  3314.     fi
  3315. }
  3316.  
  3317.  
  3318. Copy_vesafb()
  3319. {
  3320.     local trigger=/tmp/vesafb-640x480x4
  3321.  
  3322.     [ -x $trigger ] && cp -a $trigger $DIR_TARGET/var/run
  3323. }
  3324.  
  3325.  
  3326. Run_OpenLinux_Finish()
  3327. {
  3328.     if [ -x $DIR_TARGET/usr/libexec/OpenLinux/finish.sh ]; then
  3329.         Debug "Running Run_OpenLinux_Finish"
  3330.         mount -t proc /proc $DIR_TARGET/proc
  3331.         ( cd $DIR_TARGET; chroot $DIR_TARGET usr/libexec/OpenLinux/finish.sh ) > $DIR_TARGET/tmp/OpenLinux.finish.log 2>&1    
  3332.         umount $DIR_TARGET/proc
  3333.     fi
  3334. }
  3335.  
  3336.  
  3337. Run_finish()
  3338. {
  3339.     Breakpoint "Run_finish"
  3340.     echo "Debug: Running Run_finish ..." > /dev/tty4
  3341.     Set_real_root_dev
  3342.     Set_modules
  3343.     Set_lilo
  3344.     Set_MBR
  3345.     Copy_hwinfo
  3346.     Copy_mklizard
  3347.     Copy_vesafb
  3348.     Do_fix
  3349.     Do_fix_ePanic XFree_usr_adm
  3350.     Run_OpenLinux_Finish
  3351.     echo "Debug: Run_finish reached end. ok." > /dev/tty4
  3352.     return 0
  3353. }
  3354.  
  3355. Get_Floppy_Version()
  3356. {
  3357.     local floppy_num
  3358.     
  3359.     if [ -f /IDENTIFY ]; then
  3360.         floppy_num="`cut -d'#' -f 2 /IDENTIFY | cut -d' ' -f 1`"
  3361.         if [ -n "$floppy_num" ]; then
  3362.             echo "$floppy_num"
  3363.             return 0
  3364.         fi
  3365.     fi
  3366.     Debug "Ooops. Can not determine floppy version."
  3367.     return 1
  3368. }
  3369.  
  3370. Simple_Module_Manager()
  3371. {
  3372.     local probe_mode=
  3373.     local insmod_param=
  3374.     local floppy_num="`Get_Floppy_Version`"
  3375.     local floppy_info
  3376.  
  3377.     if [ -n "$floppy_num" ]; then
  3378.         floppy_info=" [build ${floppy_num}]"
  3379.     fi
  3380.  
  3381.     $CMD_BOOTER add_menu "T1 Initial hardware detection${floppy_info}:"
  3382.     $CMD_BOOTER list "L1 Hardware"
  3383.     $CMD_BOOTER add "HDEVPCI Probing for PCI devices"
  3384.     $CMD_BOOTER add "HPCMCIA Probing for PCMCIA cards"
  3385.     $CMD_BOOTER add "HCDSCSI Probing for SCSI hosts"
  3386.     $CMD_BOOTER add "HCDATAPI Probing for ATAPI CDROMs"
  3387.     $CMD_BOOTER add "HCDOTHER Probing for other CDROMs"
  3388.     $CMD_BOOTER add "HETHER Probing for Ethernet cards"
  3389.     $CMD_BOOTER end
  3390.     $CMD_BOOTER show
  3391.     $CMD_BOOTER activate L1
  3392.  
  3393.     Do_Autoprobe HDEVPCI
  3394.     $CMD_BOOTER item HPCMCIA
  3395.     if [ -z "`sed -n '/^er=/p' /tmp/cmdline | fgrep nopcmcia`" ]; then
  3396.         InitPCMCIA || $CMD_BOOTER none
  3397.     else
  3398.         $CMD_BOOTER skip
  3399.     fi
  3400.     RemovePCMCIA
  3401.  
  3402.     Breakpoint "before autoprobe"
  3403.     if [ -n "`sed -n '/^er=/p' /tmp/cmdline | fgrep cautious`" ]; then
  3404.         probe_mode=cautious
  3405.     fi
  3406.  
  3407.     # do the insmod= parameter parsing
  3408.     insmod_param="`sed -n '/^insmod=/p' /tmp/cmdline | cut -d'=' -f 2- | sed 's/%/ /g'`"
  3409.     if [ -n "$insmod_param" ]; then
  3410.         if [ "$insmod_param" = "manually" ]; then
  3411.             Breakpoint --force "insert your modules manually using insmod"
  3412.             probe_mode=nothing
  3413.         elif [ "$insmod_param" = "query" ]; then
  3414.             Breakpoint --force "now we would start the module manager"
  3415.             probe_mode=query
  3416.         else
  3417.             # after the default modules were loaded, we allow one
  3418.             # particular module to be loaded with parameters
  3419.             # specified in the form install insmod=module%param%...
  3420.             # so e.g. install insmod=ne%io=0x340%irq=4
  3421.             Do_Load_Module $insmod_param
  3422.         fi
  3423.     fi
  3424.     #Do_Autoprobe all $probe_mode
  3425.     #Do_Autoprobe HDEVPCI $probe_mode
  3426.     Do_Autoprobe HCDSCSI $probe_mode
  3427.     Do_Autoprobe HCDATAPI $probe_mode
  3428.     if [ -n "`sed -n '/^er=/p' /tmp/cmdline | fgrep noothercd`" ]; then
  3429.         $CMD_BOOTER item HCDOTHER
  3430.         $CMD_BOOTER skip
  3431.     else
  3432.         Do_Autoprobe HCDOTHER $probe_mode
  3433.     fi
  3434.     if [ -n "`sed -n '/^er=/p' /tmp/cmdline | fgrep noether`" ]; then
  3435.         $CMD_BOOTER item HETHER
  3436.         $CMD_BOOTER skip
  3437.     else
  3438.         Do_Autoprobe HETHER $probe_mode
  3439.     fi
  3440.     Breakpoint "after autoprobe"
  3441.     $CMD_BOOTER complete L1
  3442. }
  3443.  
  3444.  
  3445. Mount_Modules_Floppy()
  3446. {
  3447.     local floppy_type=scsi
  3448.     local need_floppy=no
  3449.  
  3450.     # in a small initrd some modules are missing, so ask for modules floppy
  3451.     if [ ! -f /lib/modules/`uname -r`/kernel/drivers/scsi/t128.o.gz ]; then
  3452.         need_floppy=yes
  3453.     fi
  3454.  
  3455.     # ask for PCMCIA floppy if supported chip but no PCMCIA modules found
  3456.     if [ -x /sbin/probe -a -n "`/sbin/probe | fgrep -v 'not found' | fgrep 'found'`" ]; then
  3457.         floppy_type=pcmcia
  3458.         if [ ! -f /lib/modules/`uname -r`/pcmcia/pcmcia_core.o.gz ]; then
  3459.             need_floppy=yes
  3460.         fi
  3461.     fi
  3462.  
  3463.     # if we explicitly say no modules floppy than overrule anything else
  3464.     if [ -n "`sed -n '/^er=/p' /tmp/cmdline | fgrep nofloppy`" ]; then
  3465.         need_floppy=no
  3466.     fi
  3467.  
  3468.     # if we explicitly request a scsi floppy then ...
  3469.     if [ -n "`sed -n '/^er=/p' /tmp/cmdline | fgrep scsi`" ]; then
  3470.         need_floppy=yes
  3471.     fi
  3472.  
  3473.     # do we need a floppy now?
  3474.     if [ "$need_floppy" = "no" ]; then
  3475.         return 0
  3476.     fi
  3477.  
  3478.     $CMD_BOOTER list "L0 Modules"
  3479.     $CMD_BOOTER add "MODULES Insert $floppy_type floppy"
  3480.     $CMD_BOOTER end
  3481.     $CMD_BOOTER show
  3482.     $CMD_BOOTER activate L0
  3483.     $CMD_BOOTER item MODULES
  3484.     while [ 1 ]; do
  3485.         sleep 10
  3486.         mount -r -t ext2 /dev/fd0H1440 /floppy > $FILE_LOG_DEBUG 2>&1
  3487.         if [ $? -eq 0 ]; then
  3488.             if [ -d /floppy/lib/modules ]; then
  3489.                 $CMD_BOOTER ok
  3490.                 break
  3491.             else
  3492.                 umount /floppy > $FILE_LOG_DEBUG 2>&1
  3493.             fi
  3494.         fi
  3495.         if [ -z "`sed -n '/^er=/p' /tmp/cmdline | fgrep scsi`" ]; then
  3496.             $CMD_BOOTER skip
  3497.             break
  3498.         fi
  3499.         $CMD_BOOTER fail
  3500.         # jwc - sleep 5
  3501.         $CMD_BOOTER item MODULES
  3502.     done
  3503.     $CMD_BOOTER add_menu "BLANK1"
  3504. }
  3505.  
  3506.  
  3507. Write_hwinfo()
  3508. {
  3509.     if [ "$FORCE_HWINFO" != "true" ]; then
  3510.         return 0
  3511.     fi
  3512.     umount /floppy > $FILE_LOG_DEBUG 2>&1
  3513.     if [ -x /bin/hwinfo ]; then
  3514.         echo "c" > /dev/tty1
  3515.         chvt 1
  3516.         echo "Running hwinfo..."
  3517.         /bin/hwinfo || return 1
  3518.     fi
  3519.     return 0
  3520. }
  3521.  
  3522.  
  3523. HasPCMCIA()
  3524. {
  3525.     $CMD_BOOTER wait
  3526.     Debug "searching for PCMCIA controllers with probe:"
  3527.     /sbin/probe >/tmp/pcmcia 2>&1
  3528.     if [ $? -eq 0 ]; then
  3529.         Debug "PCMCIA chip found!"
  3530.         return 0
  3531.     else
  3532.         Debug "No supported PCMCIA chip found! Skipping PCMCIA!"
  3533.         $CMD_BOOTER none
  3534.         return 1
  3535.     fi
  3536. }
  3537.  
  3538.  
  3539. UnpackPCMCIA()
  3540. {
  3541.     local i
  3542. Breakpoint "Before UnpackPCMCIA"
  3543.     mkdir -p /lib/modules/`uname -r`/pcmcia
  3544.  
  3545.     # if we unpack PCMCIA we are tight on space, so gzip some modules
  3546.     mkdir -p /tmp/stage/fs
  3547.     mv /lib/modules/`uname -r`/kernel/fs/*/*.o /tmp/stage/fs
  3548.     gzip -9 /tmp/stage/fs/*.o
  3549.     mkdir -p /tmp/stage/scsi
  3550.     mv /lib/modules/`uname -r`/kernel/drivers/scsi/*.o /tmp/stage/scsi
  3551.     gzip -9 /tmp/stage/scsi/*.o
  3552.  
  3553.     # if we run from the modules floppy then copy pcmcia stuff
  3554.     if [ -f /floppy/sbin/cardmgr.gz ]; then
  3555.         cp -a /floppy/sbin/cardmgr.gz /sbin
  3556.         cp -aR /floppy/etc/pcmcia /etc
  3557.         for i in /floppy/lib/modules/`uname -r`/pcmcia/*.gz ; do
  3558.             if [ -f $i ]; then
  3559.                 cp -a $i /lib/modules/`uname -r`/pcmcia
  3560.             fi
  3561.         done
  3562.     fi
  3563.     gunzip /lib/modules/`uname -r`/pcmcia/*.gz
  3564.     gunzip /sbin/cardmgr.gz
  3565.     gunzip /etc/pcmcia/*.gz
  3566. Breakpoint "After UnpackPCMCIA"
  3567.     return 0
  3568. }
  3569.  
  3570.  
  3571. RemovePCMCIA()
  3572. {
  3573.  
  3574.   local a
  3575. Breakpoint "Before RemovePCMCIA"
  3576.  
  3577.     rm -f /sbin/probe
  3578.     rm -f /sbin/cardmgr
  3579.     rm -f /sbin/cardmgr.gz
  3580.     rm -fr /lib/modules/`uname -r`/pcmcia
  3581.     rm -fr /etc/pcmcia
  3582.     # restore the compressed modules in case of big initrd
  3583.     if [ -d /tmp/stage ]; then
  3584.         gunzip /tmp/stage/fs/*.gz
  3585.         for a in /tmp/stage/fs/*.o; do
  3586.           mv $a /lib/modules/`uname -r`/kernel/fs/`basename $a .o`
  3587.         done
  3588.         gunzip /tmp/stage/scsi/*.gz
  3589.         mv /tmp/stage/scsi/*.o /lib/modules/`uname -r`/kernel/drivers/scsi
  3590.         rm -fr /tmp/stage
  3591.     fi
  3592. Breakpoint "After RemovePCMCIA"
  3593. }
  3594.  
  3595.  
  3596. InitPCMCIA()
  3597. {
  3598.     local pcic=
  3599.     local chip=
  3600.     local modpath=
  3601.     local retval=1
  3602.  
  3603.     modpath=/lib/modules/`uname -r`/pcmcia
  3604.  
  3605.     HasPCMCIA || return 1
  3606.  
  3607. # jwc - if we get here, we have pcmcia slots.  unpackpcmcia, below, may
  3608. # fail if the user hasn't inserted the pcmcia floppy, in which case we
  3609. # won't know which type of chip we have.  assume i82365, as this is a
  3610. # safe default.
  3611. echo i82365 > /tmp/pcmcia.chip
  3612. # jwc
  3613.  
  3614.     UnpackPCMCIA || return 1
  3615.  
  3616.     # /bin/sh /etc/rc.d/rc.pcmcia
  3617.     # this will be replaced by rc.pcmcia
  3618.     while [ 1 ]; do
  3619.         Load_Default_Modules pcmcia_core || break
  3620.         # the chip should be derived automatically from the probe command
  3621.         # see /tmp/pcmcia
  3622.         for chip in i82365 tcic ; do
  3623.             Load_Default_Modules $chip
  3624.             if [ $? -eq 0 ]; then
  3625.                 pcic=$chip
  3626.                 Load_Default_Modules ds
  3627.                 break
  3628.             fi
  3629.         done
  3630.         if [ -z "$pcic" ]; then break ; fi
  3631.         if [ ! -s /sbin/cardmgr ]; then break ; fi
  3632.         /sbin/cardmgr || break
  3633.         echo "$pcic" > /tmp/pcmcia.chip
  3634.         pcic="ok"
  3635.         break
  3636.     done
  3637.     if [ "$pcic" != "ok" ]; then
  3638.         if [ -z "$pcic" ]; then
  3639.             Debug "No supported PCMCIA chip found! Skipping PCMCIA!"
  3640.             $CMD_BOOTER none
  3641.         fi
  3642.         if [ -s /var/run/cardmgr.pid ]; then
  3643.             kill `cat /var/run/cardmgr.pid`
  3644.             sleep 1
  3645.         fi
  3646.         /sbin/rmmod ds >/dev/null 2>&1 
  3647.         /sbin/rmmod tcic >/dev/null 2>&1
  3648.         /sbin/rmmod i82365 >/dev/null 2>&1
  3649.         /sbin/rmmod pcmcia_core >/dev/null 2>&1
  3650.     else
  3651.         Debug "$chip PCMCIA chip detected!"
  3652.         Debug "Ask to insert PCMCIA cards"
  3653.         Debug ":DO_INSERT_PCMCIA_CARDS:"
  3654.         # jwc - sleep 5
  3655.         $CMD_BOOTER ok
  3656.         retval=0
  3657.     fi
  3658.     return $retval
  3659. }
  3660.  
  3661.  
  3662. Make_DISK_Devices()
  3663. {
  3664.  
  3665.     # Parse /proc/partitions for disks in the system and
  3666.     # create extra device nodes for them. Requires working makedev.
  3667.  
  3668.     (read skip ; read skip ; while read major minor size device ; do
  3669.         makedev $device
  3670.     done ) < /proc/partitions
  3671. }
  3672.  
  3673. Load_Override_Modules()
  3674. {
  3675.     local i
  3676.  
  3677.     for i in /floppy/lib/modules/override/*/* ; do
  3678.         if [ -f $i ]; then
  3679.             Load_Default_Modules `basename $(echo $i | sed s'/\.o.*//')`
  3680.         fi
  3681.     done
  3682. }
  3683.  
  3684.  
  3685. Show_Easteregg()
  3686. {
  3687.     $CMD_BOOTER add_menu "T5 Product completeness checker:"
  3688.     $CMD_BOOTER list "L5 Product"
  3689.     $CMD_BOOTER add "EART Final artwork and branding available"
  3690.     $CMD_BOOTER add "ELEGAL Final Readmes and Licence available"
  3691.     $CMD_BOOTER add "EPM Final 3rd party contracts signed"
  3692.     $CMD_BOOTER add "EMKTG Marketing rollout plan in place"
  3693.     $CMD_BOOTER add "ESALES Pricing and sales quota in place"
  3694.     $CMD_BOOTER add "EPROGS Announced programs in place"
  3695.     $CMD_BOOTER end
  3696.     $CMD_BOOTER show
  3697.     $CMD_BOOTER activate L5
  3698.     $CMD_BOOTER item EART
  3699.     sleep 5
  3700.     $CMD_BOOTER fail
  3701.     $CMD_BOOTER item ELEGAL
  3702.     sleep 3 
  3703.     $CMD_BOOTER none
  3704.     $CMD_BOOTER item EPM
  3705.     sleep 3 
  3706.     $CMD_BOOTER skip
  3707.     $CMD_BOOTER item EMKTG
  3708.     sleep 3
  3709.     $CMD_BOOTER none
  3710.     $CMD_BOOTER item ESALES
  3711.     sleep 3
  3712.     $CMD_BOOTER skip
  3713.     $CMD_BOOTER item EPROGS
  3714.     sleep 3
  3715.     $CMD_BOOTER skip
  3716.     $CMD_BOOTER add_menu "BLANKEGG"
  3717. }
  3718.  
  3719.  
  3720. Probe_Hardware()
  3721. {
  3722.     Breakpoint "Probe_Hardware"
  3723.     Mount_Modules_Floppy
  3724.     if [ -n "`sed -n '/^er=/p' /tmp/cmdline | fgrep eggs`" ]; then
  3725.         Show_Easteregg
  3726.     fi
  3727.     # load override modules
  3728.     Load_Override_Modules
  3729.     Load_Default_Modules $LIST_MODULES_DEF
  3730.     # jwc - Do_fix_ePanic ide-cd
  3731.     Simple_Module_Manager
  3732.     Load_Default_Modules sd_mod sd sr_mod sg # st
  3733.     # FIXME: currently we always return 0
  3734.     return 0
  3735. }
  3736.  
  3737.  
  3738. # very simple printf replacement, pads string arg2 to size specified in arg1
  3739. Pad_String()
  3740. {
  3741.     local strmax="$1"
  3742.     local string="$2"
  3743.     local strlen
  3744.     local strpad
  3745.     local newstring=""
  3746.  
  3747.     strlen="`echo "$2" | get_info -c`"
  3748.     strlen="`do_calc $strlen - 1`"
  3749.     strpad="`do_calc $strmax - $strlen`"
  3750.     while [ $strpad -gt 0 ]; do
  3751.         newstring=" ${newstring}"
  3752.         strpad="`do_calc $strpad - 1`"
  3753.     done
  3754.     newstring="${newstring}${string}"
  3755.     echo "$newstring"
  3756. }
  3757.  
  3758.  
  3759. # For performance reasons call sfdisk once only and cache the output
  3760. Create_sfdisk_Cache()
  3761. {
  3762.     sfdisk -s 2>/dev/null > $FILE_SFDISK_CACHE
  3763.     touch $FILE_SFDISK_CACHE
  3764. }
  3765.  
  3766.  
  3767. # Get available disk devices
  3768. Get_Disk_Devices()
  3769. {
  3770.     cat $FILE_SFDISK_CACHE | sed -n '/^\/dev\//p' | cut -d':' -f 1 | sed 's/[     ]*//g'
  3771. }
  3772.  
  3773.  
  3774. # Get the kernel's view of the geometry of a disk
  3775. Get_Disk_Geometry()
  3776. {
  3777.     local disk="$1"
  3778.  
  3779.     sfdisk -g $disk 2>/dev/null | cut -d':' -f 2 | sed '{
  3780.         s/cylinders,//
  3781.         s/heads,//
  3782.         s/sectors\/track//
  3783.         }'
  3784. }
  3785.  
  3786.  
  3787. # Get cylinder size in sectors
  3788. Get_Cylinder_Size()
  3789. {
  3790.     local disk="$1"
  3791.     local tmpfile=/tmp/disksize.tmp
  3792.     local cylinders
  3793.     local heads
  3794.     local sectors
  3795.     local cylinder_size
  3796.  
  3797.     Get_Disk_Geometry $disk > $tmpfile
  3798.     read cylinders heads sectors < $tmpfile
  3799.     rm -f $tmpfile
  3800.     
  3801.     cylinder_size="`do_calc $heads \* $sectors`"
  3802.     echo "$cylinder_size"
  3803. }
  3804.  
  3805.  
  3806. # Get the size of the specified disk
  3807. Get_Disk_Size()
  3808. {
  3809.     local disk="$1"
  3810.     local tmpfile=/tmp/disksize.tmp
  3811.     local cylinders
  3812.     local heads
  3813.     local sectors
  3814.     local disk_sectors
  3815.  
  3816.     Get_Disk_Geometry $disk > $tmpfile
  3817.     read cylinders heads sectors < $tmpfile
  3818.     rm -f $tmpfile
  3819.  
  3820.     disk_sectors="`do_calc $heads \* $sectors`"
  3821.     disk_sectors="`do_calc $disk_sectors \* $cylinders`"
  3822.     disk_sectors="`do_calc $disk_sectors - 1`"
  3823.     echo "$disk_sectors"
  3824. }
  3825.  
  3826.  
  3827. # Read list of requested mountpoints from table
  3828. Get_Mountpoints()
  3829. {
  3830.     local table="$1"
  3831.  
  3832.     cat $table | sed '/^#/d' | cut -d':' -f 1
  3833. }
  3834.  
  3835.  
  3836. # Get the next mountpoint (or first mountpoint if no mountpoint specified)
  3837. Next_Mountpoint()
  3838. {
  3839.     local mountpoints="$1"
  3840.     local mountpoint
  3841.     local i
  3842.     local found="false"
  3843.  
  3844.     if [ $# -gt 1 ]; then
  3845.         mountpoint="$2"
  3846.     else
  3847.         mountpoint=""
  3848.     fi
  3849.     for i in $mountpoints ; do
  3850.         if [ -z "$mountpoint" ]; then
  3851.             echo "$i"
  3852.             break
  3853.         fi
  3854.         if [ "$found" = "true" ]; then
  3855.             echo "$i"
  3856.             break
  3857.         fi
  3858.         if [ "$i" = "$mountpoint" ]; then
  3859.             found="true"
  3860.         fi
  3861.     done
  3862. }
  3863.  
  3864. # round number of sectors up or down to the next cylinder boundary
  3865. Round_Cyl()
  3866. {
  3867.     local disk="$1"
  3868.     local direction="$2"
  3869.     local size_sectors="$3"
  3870.     local rounded_sectors
  3871.     local cylinder_size
  3872.     local cylinders
  3873.  
  3874.     cylinder_size="`Get_Cylinder_Size $disk`"
  3875.     cylinders="`do_calc $size_sectors / $cylinder_size`"
  3876.     rounded_sectors="`do_calc $cylinders \* $cylinder_size`"
  3877.     if [ "$direction" = "up" -a $rounded_sectors -lt $size_sectors ]; then
  3878.         rounded_sectors="`do_calc $rounded_sectors + $cylinder_size`"
  3879.     fi
  3880.     echo "$rounded_sectors"
  3881. }
  3882.  
  3883. # write one sfdisk line in dump format for the specified mountpoint
  3884. Write_sfdisk_Entry()
  3885. {
  3886.     local mountpoint
  3887.     local table
  3888.     local disk
  3889.     local part_num
  3890.     local start
  3891.     local outfile
  3892.     local partition
  3893.     local raw_end=
  3894.     local end=
  3895.     local size_mb
  3896.     local size_sectors
  3897.     local remain_sectors
  3898.     local part_id
  3899.     local boot_flag
  3900.     local info
  3901.     local disk_prefix
  3902.     local part_prefix
  3903.     local disk_sectors
  3904.     local next_start
  3905.     local next_sectors
  3906.  
  3907.     table="$1"
  3908.     mountpoint="$2"
  3909.     disk="$3"
  3910.     part_num="$4"
  3911.     start="$5"
  3912.     outfile="$6"
  3913.     shift 6
  3914.  
  3915.     disk_sectors="`Get_Disk_Size $disk`"
  3916.     remain_sectors="`do_calc $disk_sectors - $start`"
  3917.     remain_sectors="`do_calc $remain_sectors + 1`"
  3918.     info="`sed -n "\,^${mountpoint}:,p" $table`"
  3919.     size_mb="`echo $info | cut -d':' -f 2`"
  3920.     part_id="`echo $info | cut -d':' -f 3`"
  3921.     boot_flag="`echo $info | cut -d':' -f 4`"
  3922.     if [ -z "$size_mb" ]; then
  3923.         # as disk_sectors was calculated as a multiple of cylinders
  3924.         # we end for sure on a cylinder boundary
  3925.         size_sectors="`do_calc $disk_sectors - $start`"
  3926.         size_sectors="`do_calc $size_sectors + 1`"
  3927.         if [ $part_num -ge 4 -a $size_sectors -lt $remain_sectors ]; then
  3928.             size_sectors="`do_calc $size_sectors - 63`"
  3929.         fi
  3930.     else
  3931.         size_sectors="`do_calc $size_mb \* 2048`"
  3932.         raw_end="`do_calc $start + $size_sectors`"
  3933.         # reserve extra space for extended/logical partition chaining
  3934.         if [ $part_num -ge 4 -a $size_sectors -lt $remain_sectors ]; then
  3935.             raw_end="`do_calc $raw_end + 63`"
  3936.         fi
  3937.         # now make sure we end up on the next cylinder boundary
  3938.         raw_end="`Round_Cyl $disk up $raw_end`"
  3939.         size_sectors="`do_calc $raw_end - $start`"
  3940.         if [ $part_num -ge 4 -a $size_sectors -lt $remain_sectors ]; then
  3941.             size_sectors="`do_calc $size_sectors - 63`"
  3942.         fi
  3943.     fi
  3944.     end="`do_calc $start + $size_sectors`"
  3945.     end="`do_calc $end - 1`"
  3946.     if [ $part_num -ge 4 -a $size_sectors -lt $remain_sectors ]; then
  3947.         end="`do_calc $end + 63`"
  3948.     fi
  3949.  
  3950.     # does the requested partition fit on this disk?
  3951.     if [ $end -gt $disk_sectors ]; then
  3952.         return 1
  3953.     fi
  3954.  
  3955.     disk_prefix="`echo $disk | cut -c 6-7`"
  3956.     case $disk_prefix in
  3957.     hd|sd|xd)
  3958.         part_prefix=""
  3959.         ;;
  3960.     *)
  3961.         part_prefix="p"
  3962.         ;;
  3963.     esac
  3964.  
  3965.     partition="${disk}${part_prefix}${part_num}"
  3966.     if [ $part_num -eq 4 ]; then
  3967.         # create an extended partition
  3968.         remain_sectors="`do_calc $disk_sectors - $start`"
  3969.         remain_sectors="`do_calc $remain_sectors + 1`"
  3970.         echo "$partition : start=`Pad_String 9 $start`, size=`Pad_String 8 $remain_sectors`, Id= 5" >> $outfile
  3971.         echo >> $outfile
  3972.         start="`do_calc $start + 63`"
  3973.     fi
  3974.     if [ $part_num -ge 4 ]; then
  3975.         part_num="`do_calc $part_num + 1`"
  3976.         partition="${disk}${part_prefix}${part_num}"
  3977.     fi
  3978.     echo "$mountpoint:$partition" >> $FILE_FSINFO_MAP
  3979.     echo -n "$partition : start=`Pad_String 9 $start`, size=`Pad_String 8 $size_sectors`, Id=`Pad_String 2 $part_id`" >> $outfile
  3980.     if [ "$boot_flag" = "1" ]; then
  3981.         echo ", bootable" >> $outfile
  3982.     else
  3983.         echo >> $outfile
  3984.     fi
  3985.     if [ $part_num -ge 5 ]; then
  3986.         next_start="`do_calc $start + $size_sectors`"
  3987.         next_sectors="`do_calc $remain_sectors - $size_sectors`"
  3988.         next_sectors="`do_calc $next_sectors - 63`"
  3989.         if [ $size_sectors -lt $remain_sectors ]; then
  3990.             echo "    -     : start=`Pad_String 9 $next_start`, size=`Pad_String 8 $next_sectors`, Id= 5" >> $outfile
  3991.         else
  3992.             next_start="`do_calc $start - 63`"
  3993.             echo "    -     : start=`Pad_String 9 $next_start`, size=`Pad_String 8 0`, Id= 0" >> $outfile
  3994.         fi
  3995.         next_start="`do_calc $start - 63`"
  3996.         echo "    -     : start=`Pad_String 9 $next_start`, size=`Pad_String 8 0`, Id= 0" >> $outfile
  3997.         echo "    -     : start=`Pad_String 9 $next_start`, size=`Pad_String 8 0`, Id= 0" >> $outfile
  3998.         echo >> $outfile
  3999.     fi
  4000.     if [ $part_num -ge 5 -a $size_sectors -lt $remain_sectors ]; then
  4001.         echo "`do_calc $end + 64`"
  4002.     else
  4003.         echo "`do_calc $end + 1`"
  4004.     fi
  4005.     return 0
  4006. }
  4007.  
  4008.  
  4009. # Read a partitioning config file and create sfdisk dump output to stdout
  4010. Create_sfdisk_Dump()
  4011. {
  4012.     local disk_devices
  4013.     local mountpoints
  4014.     local mountpoint=""
  4015.     local disk
  4016.     local size
  4017.     local start=63
  4018.     local table="$1"
  4019.     local outfile="$2"
  4020.     local disk_full="false"
  4021.  
  4022.     if [ $# -ne 2 ]; then
  4023.         Panic "Usage: Create_sfdisk_Dump partitioning_config_file sfdisk_write_config_file"
  4024.     fi
  4025.     if [ ! -f "$table" ]; then
  4026.         Panic "$table: partitioning_config_file not found"
  4027.     fi
  4028.  
  4029.     rm -f $outfile
  4030.     Create_sfdisk_Cache
  4031.  
  4032.     disk_devices="`Get_Disk_Devices`"
  4033.     mountpoints="`Get_Mountpoints $table`"
  4034.     mountpoint="`Next_Mountpoint "$mountpoints"`"
  4035.  
  4036.     # We fill up disks sequentially as found by 'sfdisk'
  4037.     for disk in $disk_devices ; do
  4038.         # reset variables and print header for every new disk started
  4039.         part_num=1
  4040.         disk_full="false"
  4041.         echo "# partition table of $disk" >> $outfile
  4042.         echo "unit: sectors" >> $outfile
  4043.         echo >> $outfile
  4044.         while [ 1 ]; do
  4045.             start="`Write_sfdisk_Entry $table $mountpoint $disk $part_num $start $outfile`"
  4046.             if [ $? -ne 0 ]; then
  4047.                 disk_full="true"
  4048.                 start="63"
  4049.                 echo >> $outfile
  4050.                 break
  4051.             fi
  4052.             disk_full="false"
  4053.             mountpoint="`Next_Mountpoint "$mountpoints" $mountpoint`"
  4054.             if [ -z "$mountpoint" ]; then
  4055.                 break
  4056.             fi
  4057.             part_num="`do_calc $part_num + 1`"
  4058.         done
  4059.         if [ "$disk_full" = "true" ]; then
  4060.             continue
  4061.         fi
  4062.         if [ -z "$mountpoint" ]; then
  4063.             break
  4064.         fi
  4065.     done
  4066.     if [ "$disk_full" = "true" ]; then
  4067.         Panic "You don't have enough diskspace for all the partitions"
  4068.     fi
  4069.     rm -f $FILE_SFDISK_CACHE
  4070.     return 0
  4071. }
  4072.  
  4073.  
  4074. Get_Dev_Of_FSINFO_MAP()
  4075. {
  4076.     sed -n "\,^$1:,p" $FILE_FSINFO_MAP | cut -d':' -f 2
  4077. }
  4078.  
  4079.  
  4080. Prepare_Remaining_Partitions()
  4081. {
  4082.     local mountpoints
  4083.     local mountpoint
  4084.     local device
  4085.     local info
  4086.     local fstype
  4087.     local format_flag
  4088.     local use_flag
  4089.     local mount_options
  4090.     local dump_flag
  4091.     local fsck_flag
  4092.     local format_cmd
  4093.     local format_opts
  4094.  
  4095.     mountpoints="`Get_Mountpoints $FILE_FSINFO_MAP`"
  4096.  
  4097.     # loop through all mountpoints
  4098.     for mountpoint in $mountpoints ; do
  4099.         # The '/' and 'swap' partitions were handled before already
  4100.         if [ "$mountpoint" = '/' -o "$mountpoint" = 'swap' ]; then
  4101.             continue
  4102.         fi
  4103.         device="`Get_Dev_Of_FSINFO_MAP $mountpoint`"
  4104.         info="`sed -n "\,^${mountpoint}:,p" $FILE_LIZARD_FSINFO`"
  4105.         fstype="`echo $info | cut -d':' -f 5`"
  4106.         if [ -z "$fstype" ]; then
  4107.             fstype="ext2"
  4108.         fi
  4109.         format_flag="`echo $info | cut -d':' -f 6`"
  4110.         use_flag="`echo $info | cut -d':' -f 7`"
  4111.         mount_options="`echo $info | cut -d':' -f 8`"
  4112.         dump_flag="`echo $info | cut -d':' -f 9`"
  4113.         fsck_flag="`echo $info | cut -d':' -f 10`"
  4114.         if [ "$format_flag" = '1' ]; then
  4115.             Debug "Creating and mounting root filesystem ($myroot)"
  4116.             format_opts=""
  4117.             case $fstype in
  4118.             ext2|ext3|reiserfs)
  4119.                 if [ "$fstype" = "reiserfs" ]; then
  4120.                     format_cmd="mkreiserfs"
  4121.                 elif [ "$fstype" = "ext2" ]; then
  4122.                     format_cmd="mke2fs"
  4123.                 else
  4124.                     format_cmd="mke2fs"
  4125.                     format_opts="-j"
  4126.                 fi
  4127.                 Debug "Formating $device as $fstype with $format_cmd" 
  4128.                 $format_cmd $format_opts $device > /dev/tty4 2>&1 || Panic "$format_cmd $device failed"
  4129.                 ;;
  4130.             *)
  4131.                 Panic "Formating of type $fstype not supported"
  4132.                 ;;
  4133.             esac
  4134.         fi
  4135.         if [ "$use_flag" = '1' ]; then
  4136.             Debug "Mounting $device of type $fstype to /mnt/root${mountpoint}"
  4137.             mkdir -p /mnt/root${mountpoint}  > /dev/tty4 2>&1 || Panic "mkdir -p /mnt/root${mountpoint} failed"
  4138.             mount -t $fstype $device /mnt/root${mountpoint}  > /dev/tty4 2>&1 || Panic "mount -t $fstype $device /mnt/root${mountpoint} failed"
  4139.             if [ -z "$mount_options" ]; then
  4140.                 mount_options="defaults"
  4141.             fi
  4142.         else
  4143.             if [ -z "$mount_options" ]; then
  4144.                 mount_options="defaults,noauto"
  4145.             fi
  4146.         fi
  4147.         if [ -z "$dump_flag" ]; then
  4148.             dump_flag="0"
  4149.         fi
  4150.         if [ -z "$fsck_flag" ]; then
  4151.             fsck_flag="0"
  4152.         fi
  4153.         # Write fstab entry
  4154.         mkdir -p /mnt/root/etc
  4155.         cat << EOF >> /mnt/root/etc/fstab
  4156. $device $mountpoint $fstype $mount_options $dump_flag $fsck_flag
  4157. EOF
  4158.     done
  4159. }
  4160.  
  4161.  
  4162. Run_lizard_pre_script()
  4163. {
  4164.     local myroot
  4165.     local myswap
  4166.     local sfdisk_feed_file=/tmp/sfdisk.dump.feed
  4167.     local disks
  4168.     local disk
  4169.  
  4170.     # As the very first step run the start.sh script.
  4171.     # Put all your pre fixes and adjustments here.
  4172.     # For some ideas look at the examples in our template.
  4173.     Breakpoint "Run_lizard_pre_script"
  4174.     if [ -n "$FILE_LIZARD_START" ]; then
  4175.         if [ -f $FILE_LIZARD_START ]; then
  4176.             Debug "Running $FILE_LIZARD_START ..."
  4177.             #echo "c" > /dev/tty4
  4178.             echo "Running $FILE_LIZARD_START ..." > /dev/tty4
  4179.             chvt 4
  4180.             sh $FILE_LIZARD_START
  4181.             chvt 7
  4182.         fi
  4183.     fi
  4184.  
  4185.     if [ -z "$FILE_LIZARD_FSINFO" ]; then
  4186.         chvt 4
  4187. #        echo "Skipping fsinfo file handling (backward compatibility mode)" > /dev/tty4
  4188.         myroot="`get_val -f $FILE_LIZARD_PROFILE CONF_INSTALL_ROOT`"
  4189.         myswap="`get_val -f $FILE_LIZARD_PROFILE CONF_INSTALL_SWAP`"
  4190.     else
  4191.         if [ -f $FILE_LIZARD_FSINFO ]; then
  4192.             echo "Generating dump table for sfdisk from fsinfo file..." > /dev/tty4
  4193.             Create_sfdisk_Dump $FILE_LIZARD_FSINFO $sfdisk_feed_file
  4194.             cat $sfdisk_feed_file > /dev/tty4
  4195.             # split the file in one file per disk
  4196.             echo "# END" >> $sfdisk_feed_file
  4197.             disks="`sed -n '/^# partition table of/s/^# partition table of //p' $sfdisk_feed_file`"
  4198.             for disk in $disks ; do
  4199.                 echo "Partitioning disk $disk ..."
  4200.                 sed -n "\;^# partition table of $disk;,/^#/p" /tmp/sfdisk.dump.feed | sed '$,$d' > ${sfdisk_feed_file}.tmp
  4201.                 cat ${sfdisk_feed_file}.tmp
  4202.                 sfdisk -x $disk < ${sfdisk_feed_file}.tmp || Panic "Partitioning of disk $disk by using sfdisk failed"
  4203.                 Replace_MBR $disk || Panic "Replacing of MBR of disk $disk failed"
  4204.             done
  4205.             myroot="`Get_Dev_Of_FSINFO_MAP '/'`"
  4206.             myswap="`Get_Dev_Of_FSINFO_MAP 'swap'`"
  4207.         else
  4208.             Debug "$FILE_LIZARD_FSINFO: file not found"
  4209.             retval=1
  4210.         fi
  4211.     fi
  4212.  
  4213.     if [ -n "$myswap" ]; then
  4214.         Debug "Creating and using swap space ($myswap)"
  4215.         mkswap $myswap > /dev/tty4 2>&1 || return 1
  4216.         swapon $myswap > /dev/tty4 2>&1 || return 1
  4217.     else
  4218.         Debug "Warning: no swap partition specified"
  4219.     fi
  4220.  
  4221.     if [ -n "$myroot" ]; then
  4222.         Debug "Creating and mounting root filesystem ($myroot)"
  4223.         mke2fs -j $myroot > /dev/tty4 2>&1 || return 1
  4224.         mount -t ext3 $myroot /mnt/root > /dev/tty4 2>&1 || return 1
  4225.     else
  4226.         Debug "Abort: no root partition specified"
  4227.         return 1
  4228.     fi
  4229.     
  4230.     mkdir -p /mnt/root/etc
  4231.     cat << EOF > /mnt/root/etc/fstab
  4232. $myroot / ext3 defaults 1 1
  4233. EOF
  4234.     if [ -n "$myswap" ]; then
  4235.         cat << EOF >> /mnt/root/etc/fstab
  4236. $myswap swap swap defaults 0 0
  4237. EOF
  4238.     fi
  4239.     chmod 644 /mnt/root/etc/fstab
  4240.     Prepare_Remaining_Partitions
  4241. }
  4242.  
  4243.  
  4244. # Copy_Val SOURCE_VARIABLE [SOURCE_FILE TARGET_VARIABLE] TARGET_FILE [DEFAULTVALUE]
  4245. Copy_Val()
  4246. {
  4247.     local srcvar
  4248. #    local srcfile="/etc/system.cnf"
  4249.     local srcfile="/mnt/root/etc/system.cnf"
  4250.     local tgtvar
  4251.     local tgtfile
  4252.     local defval=""
  4253.     local val=""
  4254.  
  4255.     var="$1"
  4256.     shift 1
  4257.     tgtvar="$var"
  4258.     if [ $# -gt 2 ]; then
  4259.         srcfile="$1"
  4260.         tgtvar="$2"
  4261.         shift 2
  4262.     fi
  4263.     tgtfile="$1"
  4264.     shift 1
  4265.     if [ $# -gt 0 ]; then
  4266.         defval="$1"
  4267.         shift 1
  4268.     fi
  4269.  
  4270.     if [ -f $srcfile ]; then
  4271.         val="`get_val -f $srcfile $var`"
  4272.         if [ -z "$val" ]; then
  4273.             val="$defval"
  4274.         fi
  4275.     else
  4276.         val="$defval"
  4277.     fi
  4278.     touch $tgtfile
  4279.     set_val -f $tgtfile $tgtvar "$val"
  4280. }
  4281.  
  4282. Retrieve_sysinfo()
  4283. {
  4284.     local bpf=/tmp/bootpc.out
  4285.  
  4286. # Fix_etc_fstab
  4287. # parse provided /etc/fstab
  4288. # create mountpoints
  4289. # mount filesystems
  4290.  
  4291. # Fix_timezone
  4292. Copy_Val CONF_TIMEZONE /tmp/clock "GMT"
  4293. Copy_Val CONF_KERNTZ_FLAG /tmp/clock "u"
  4294.  
  4295. # Fix_mouse
  4296. Copy_Val CONF_MOUSE1_DEV /tmp/mouse "/dev/psaux"
  4297. Copy_Val CONF_MOUSE1_BUTTONS /tmp/mouse "3"
  4298. Copy_Val CONF_MOUSE1_X_TYPE /tmp/mouse "ps/2"
  4299.  
  4300. # Fix_XFree86
  4301. Copy_Val CONF_X_SERVER1_TYPE /tmp/xserver "XFree86"
  4302. #Copy_Val CONF_X_SERVER1_RESOL /tmp/xserver ""
  4303. #Copy_Val CONF_X_KEYBOARD_MAP /tmp/xserver ""
  4304.  
  4305. # Fix_network
  4306. Copy_Val CONF_eth0_STAT /tmp/network ""
  4307. Copy_Val CONF_eth0_IP /tmp/network "192.168.1.2"
  4308. Copy_Val CONF_eth0_MASK /tmp/network "255.255.255.0"
  4309. Copy_Val CONF_eth0_DYNAMIC /tmp/network ""
  4310. Copy_Val CONF_ROUTER1_IP /tmp/network "192.168.1.1"
  4311. Copy_Val CONF_FQ_HOSTNAME /tmp/network "noname.nodomain.none"
  4312. Copy_Val CONF_DNS_SERVER1_IP /tmp/network ""
  4313. Copy_Val CONF_DNS_SERVER2_IP /tmp/network ""
  4314. Copy_Val CONF_DNS_SERVER3_IP /tmp/network ""
  4315. Copy_Val CONF_NIS_DOMAIN /tmp/network ""
  4316. Copy_Val CONF_NIS_SERVER1_IP /tmp/network ""
  4317. Copy_Val CONF_NIS_SERVER2_IP /tmp/network ""
  4318. Copy_Val CONF_NIS_SERVER3_IP /tmp/network ""
  4319.  
  4320. # overwrite the network info if we have DHCP info
  4321. if [ -s $bpf ]; then
  4322.     Copy_Val HOSTNAME $bpf CONF_FQ_HOSTNAME /tmp/network
  4323.     Copy_Val IPADDR $bpf CONF_eth0_IP /tmp/network
  4324.     Copy_Val NETMASK $bpf CONF_eth0_MASK /tmp/network
  4325.     Copy_Val GATEWAYS $bpf CONF_ROUTER1_IP /tmp/network
  4326.     Copy_Val DNSSRVS $bpf CONF_DNS_SERVER1_IP /tmp/network
  4327. fi
  4328.  
  4329. # Fix_logins
  4330. # nothing to do
  4331. # copy passwd and group
  4332.  
  4333. # Fix_lisa
  4334. # nothing to do
  4335. # set DIR_TARGET to /
  4336.  
  4337. # Fix_language
  4338. # FIXME: has to be converted from CONF_LANGUAGE to CONF_LST_LANG
  4339. Copy_Val CONF_LST_LANG /etc/system.cnf CONF_LANGUAGE /tmp/language "english"
  4340.  
  4341.  
  4342. }
  4343.  
  4344.  
  4345. Run_lizard_unattended()
  4346. {
  4347.     local retval
  4348.  
  4349.     Breakpoint "Run_lizard_unattended"
  4350.     Debug "Running Run_lizard_unattended"
  4351.     chvt 4
  4352.     if [ -f $FILE_LIZARD_PKGS ]; then
  4353.         echo "Running $DIR_LIVE_LIZARD/share/apps/lizard/extrabin/instpkg.sh $FILE_LIZARD_PKGS..." > /dev/tty4
  4354.         $DIR_LIVE_LIZARD/share/apps/lizard/extrabin/instpkg.sh $FILE_LIZARD_PKGS > /dev/tty4
  4355.     else
  4356.         Debug "$FILE_LIZARD_PKGS: file not found"
  4357.         retval=1
  4358.     fi
  4359.     retval=$?
  4360.     chvt 7
  4361.     if [ $retval -eq 0 ]; then
  4362.         $CMD_BOOTER ok
  4363.     else
  4364.         $CMD_BOOTER fail
  4365.         sleep 1
  4366.     fi
  4367.     if [ -f $FILE_LIZARD_XCONFIG ]; then
  4368.         Debug "Copying XF86Config"
  4369.         mkdir -p $DIR_TARGET/etc/X11
  4370. #        cp -a $FILE_LIZARD_XCONFIG $DIR_TARGET/etc/XF86Config
  4371.         cp -a $FILE_LIZARD_XCONFIG $DIR_TARGET/etc/X11/XF86Config-4
  4372.     fi
  4373. #    cp -a $FILE_LIZARD_PROFILE /etc/system.cnf
  4374.     cp -a $FILE_LIZARD_PROFILE $DIR_TARGET/etc/system.cnf
  4375.     Debug "Retrieving system configuration"
  4376.     Breakpoint "After file copy"
  4377.     Retrieve_sysinfo
  4378.     return $retval
  4379. }
  4380.  
  4381.  
  4382. Run_lizard_post_script()
  4383. {
  4384.     local eth0_ip="`get_val CONF_eth0_IP`"
  4385.     local eth0_net="`get_val CONF_eth0_NET`"
  4386.     local file_passwd=etc/passwd
  4387.     local file_shadow=etc/shadow
  4388.     local rootpw_passwd=""
  4389.     local rootpw_shadow=""
  4390.  
  4391.     chvt 4
  4392.     Debug "Running Run_lizard_post_script ..."
  4393.     Breakpoint "Before Run_lizard_post_script - what is /etc/passwd?"
  4394.     echo "Running Run_lizard_post_script ..." > /dev/tty4
  4395.  
  4396.     # get root password from an old passwd file (if available)
  4397.     file_passwd="`Lizard_File_Glob $file_passwd $eth0_ip $eth0_net`"
  4398.     if [ -n "$file_passwd" ]; then
  4399.         rootpw_passwd="`sed -n '/^root:/p' $file_passwd | cut -d':' -f 2`"
  4400.     fi
  4401.  
  4402.     # get root password from an old shadow file (if available)
  4403.     file_shadow="`Lizard_File_Glob $file_shadow $eth0_ip $eth0_net`"
  4404.     if [ -n "$file_shadow" ]; then
  4405.         rootpw_shadow="`sed -n '/^root:/p' $file_shadow | cut -d':' -f 2`"
  4406.     fi
  4407.  
  4408.  
  4409.     if [ -z "$rootpw_passwd" ]; then
  4410.         rootpw_passwd="x"
  4411.     fi
  4412.     if [ -z "$rootpw_shadow" ]; then
  4413.         rootpw_shadow="x"
  4414.     fi
  4415.  
  4416.     # if we have an old shadow password but no shadow in the target system
  4417.     # then we better take the old shadow password and put it in /etc/passwd
  4418.     if [ ! -f $DIR_TARGET/etc/shadow -a -n "$rootpw_shadow" ]; then
  4419.         rootpw_passwd="$rootpw_shadow"
  4420.     fi
  4421.  
  4422.     # Make sure we have a root password set in /etc/passwd
  4423.     if [ -z "`sed -n '/^root:/p' $DIR_TARGET/etc/passwd | cut -d':' -f 2`" ]; then
  4424.         echo "root:$rootpw_passwd:0:0:root:/root:/bin/bash" > $DIR_TARGET/etc/passwd.tmp
  4425.         sed "/^root:/d" $DIR_TARGET/etc/passwd >> $DIR_TARGET/etc/passwd.tmp
  4426.         chmod 644 $DIR_TARGET/etc/passwd.tmp
  4427.         mv $DIR_TARGET/etc/passwd.tmp $DIR_TARGET/etc/passwd
  4428.     fi
  4429.  
  4430.     # Make sure we have a root password set in /etc/shadow
  4431.     if [ -f $DIR_TARGET/etc/shadow ]; then
  4432.         echo "root:$rootpw_shadow:10547:0::7:7::" > $DIR_TARGET/etc/shadow.tmp
  4433.         sed '/^root:/d' $DIR_TARGET/etc/shadow >> $DIR_TARGET/etc/shadow.tmp
  4434.         chmod 400 $DIR_TARGET/etc/shadow.tmp
  4435.         mv $DIR_TARGET/etc/shadow.tmp $DIR_TARGET/etc/shadow
  4436.     fi
  4437.  
  4438.     # As the last step run the finish.sh script.
  4439.     # Put all your post fixes and adjustments here.
  4440.     Breakpoint "Run_lizard_post_script"
  4441.     if [ -n "$FILE_LIZARD_FINISH" ]; then
  4442.         if [ -f $FILE_LIZARD_FINISH ]; then
  4443.             Debug "Running $FILE_LIZARD_FINISH ..."
  4444.             echo "Running $FILE_LIZARD_FINISH ..." > /dev/tty4
  4445.             chvt 4
  4446.             sh $FILE_LIZARD_FINISH
  4447.             chvt 7
  4448.         fi
  4449.     fi
  4450. }
  4451.  
  4452.  
  4453. Do_Demo_Fake()
  4454. {
  4455.     local dangerous_bins="/bin/instpkg.sh /bin/instpkg /sbin/lilo /sbin/mkfs.ext2 /sbin/mkswap /sbin/swapon /sbin/sfdisk"
  4456.  
  4457.     if [ "$1" = "enable" ]; then
  4458.         for i in $dangerous_bins ; do
  4459.             if [ -f $i ]; then
  4460.                 mv $i $i.real
  4461.             fi
  4462.             if [ -f $DIR_LIVE_LIZARD/share/apps/lizard/extrabin/fake-`basename $i` ]; then
  4463.                 ln -s $DIR_LIVE_LIZARD/share/apps/lizard/extrabin/fake-`basename $i` $i
  4464.             else
  4465.                 # this one is only for fake-sfdisk and only
  4466.                 # temporary until it's integrated into lizard
  4467.                 ln -s fake-`basename $i` $i
  4468.                 # well it's also for instpkgs.sh
  4469.             fi
  4470.         done
  4471.     elif [ "$1" = "disable" ]; then
  4472.         for i in $dangerous_bins ; do
  4473.             if [ -f $i.real ]; then
  4474.                 rm -f $i
  4475.                 mv $i.real $i
  4476.             fi
  4477.         done
  4478.     fi
  4479. }
  4480.  
  4481.  
  4482. Mini_lizard()
  4483. {
  4484.     Do_Mount_Source || return 1
  4485.     $CMD_BOOTER complete L2
  4486.     Debug ":FOUND_VALID_SOURCE:"
  4487.     $CMD_BOOTER add_menu "BLANK3"
  4488.     $CMD_BOOTER add_menu "T3 Lycoris Install Wizard:"
  4489.     if [ -f $FILE_LIZARD_RULES ]; then
  4490.         $CMD_BOOTER add 'LIZARD Starting LUI - Lizard Unattended Install'
  4491.     else
  4492.         if [ -n "`sed -n '/^er=/p' /tmp/cmdline | fgrep text`" ]; then
  4493.             $CMD_BOOTER add 'LIZARD Starting LISA - text based install'
  4494.         else
  4495.             $CMD_BOOTER add 'LIZARD Starting LIZARD'
  4496.         fi
  4497.     fi
  4498.     $CMD_BOOTER item LIZARD
  4499.     $CMD_BOOTER list "L3 Lizard"
  4500.     $CMD_BOOTER end
  4501.     $CMD_BOOTER show
  4502.     $CMD_BOOTER activate L3
  4503.     if [ -n "`sed -n '/^er=/p' /tmp/cmdline | fgrep text`" ]; then
  4504.         Prepare_lisa || return 1
  4505.     else
  4506.         Prepare_lizard || return 1
  4507.     fi
  4508.     # Write hwinfo (if requested) after install source was mounted
  4509.     Write_hwinfo
  4510.     chvt 7
  4511.     if [ -f $FILE_LIZARD_RULES ]; then
  4512.         Run_lizard_pre_script || return 1
  4513.     fi
  4514.     if [ -f $FILE_LIZARD_RULES ]; then
  4515.         Run_lizard_unattended || return 1
  4516.     else
  4517.         if [ -n "`sed -n '/^er=/p' /tmp/cmdline | fgrep demo`" ]; then
  4518.             Do_Demo_Fake enable
  4519.         fi
  4520.         if [ -n "`sed -n '/^er=/p' /tmp/cmdline | fgrep text`" ]; then
  4521.             Run_lisa_install || return 1
  4522.         else
  4523.             Run_lizard_interactive || return 1
  4524.         fi
  4525.         # link all programs back to the dangerous ones
  4526.         if [ -n "`sed -n '/^er=/p' /tmp/cmdline | fgrep demo`" ]; then
  4527.             Do_Demo_Fake disable
  4528.         fi
  4529.     fi
  4530.     $CMD_BOOTER list "L4 Finish"
  4531.     $CMD_BOOTER add "FINISH Preparing to boot into new system"
  4532.     $CMD_BOOTER end
  4533.     $CMD_BOOTER show
  4534.     $CMD_BOOTER activate L4
  4535.     $CMD_BOOTER item FINISH
  4536.     if [ -n "`sed -n '/^er=/p' /tmp/cmdline | fgrep demo`" ]; then
  4537.         Set_real_root_dev || return 1
  4538.     else
  4539.         Run_finish || return 1
  4540.     fi
  4541.     $CMD_BOOTER ok
  4542.     if [ -f $FILE_LIZARD_RULES ]; then
  4543.         Run_lizard_post_script || return 1
  4544.     fi
  4545.     Unmount_install_partitions
  4546.     return 0
  4547. }
  4548.  
  4549.  
  4550. Check_vesafb()
  4551. {
  4552.     cat /proc/kmsg > /tmp/kmsg &
  4553.     sleep 3; kill $! > /dev/null 2>&1
  4554.     if [ -z "`sed -n '/vesafb: mode is 640x480x4/p' /tmp/kmsg`" ]; then
  4555.         Debug "apparently not in vesafb-mode 640x480x4..."
  4556.         return 1
  4557.     fi
  4558.     touch /tmp/vesafb-640x480x4
  4559.     return 0
  4560. }
  4561.  
  4562.  
  4563. Main()
  4564. {
  4565.     local retval
  4566.  
  4567.     Debug "Running new /linuxrc ..."
  4568.  
  4569.     Mini_init boot
  4570.     Check_vesafb || CMD_BOOTER=booter.text
  4571.     if [ -n "`sed -n '/^er=/p' /tmp/cmdline | fgrep eggs`" ]; then
  4572.         if [ -f /boot/stage3-egg.pcx ]; then
  4573.             mv /boot/stage3-egg.pcx /boot/stage3.pcx
  4574.         fi
  4575.     else
  4576.         rm -f /boot/stage3-egg.pcx
  4577.     fi
  4578.     $CMD_BOOTER -server
  4579.     # syslinux puts the kernel name in BOOT_IMAGE - overwrite with label
  4580.     if [ -n "`sed -n '/^BOOT_IMAGE=boot/p' /tmp/cmdline`" ]; then
  4581.         BOOT_IMAGE=boot
  4582.     fi
  4583.     if [ "$BOOT_IMAGE" = "boot" ]; then
  4584.         Probe_Hardware
  4585.         Set_real_root_dev cmdline
  4586.     else
  4587.         # goto multi user mode
  4588.         Mini_init multi
  4589.         Probe_Hardware
  4590.         # probe hardware, mount CDROM, call lizard, finish install
  4591.         Mini_lizard
  4592.         retval=$?
  4593.         if [ $retval -ne 0 ]; then
  4594.             $CMD_BOOTER fail
  4595.             Install_aborted
  4596.         fi
  4597.         # goto single user mode
  4598.         Mini_init single
  4599.     fi
  4600.     Kill_Proc_By_Name XF86_VGA16 lwm
  4601.     Kill_Proc_By_Name booter hotplugd
  4602.  
  4603.     # fix for broken docview
  4604.     Kill_Proc_By_Name docview
  4605.  
  4606.     # remove ide-cd module, so we can switch to ide-scsi mode later
  4607.     Do_fix_ePanic no-ide-cd
  4608.  
  4609.     echo "c" > /dev/tty1
  4610.     chvt 1 
  4611.     echo "c" > /dev/tty7
  4612.     Mini_init shutdown
  4613.     Breakpoint "before quitting initrd"
  4614. }
  4615.  
  4616.  
  4617. Main
  4618. if [ "$FORCE_REBOOT" = "true" ]; then
  4619.     /sbin/reboot
  4620. else
  4621.     exit 0
  4622. fi
  4623.  
  4624.